Skip to content
Oracle Home

Oracle Home

For Everything Oracle and more

Menu

  • Home
  • Articles
  • About Me
  • Computer Book Reviews
  • New Computer Books

MySQL Code

You are here: Oracle Home > MySQL Code

How to count the number of occurences in a MySQL string

There is currently no built-in function to do this, so I use: SELECT LENGTH( ‘THIS TEST’ ) – LENGTH( REPLACE (‘THIS TEST’,’T’,”); Answer output is: 3

orahome 19/09/2018 MySQL Code No Comments Read more

How to show records for Last Month, This Month, Last Week, This Week, Last Year, This Year in MySQL

Just add these AND SQL statements to your queries, in these examples the ORDER_DATE is your column name which holds the date you are comparing against. This Week AND YEARWEEK(ORDER_DATE) = YEARWEEK(CURRENT_DATE) Last Week AND YEARWEEK(ORDER_DATE) = YEARWEEK(CURRENT_DATE – INTERVAL

orahome 19/09/2018 MySQL Code No Comments Read more

How to find all the duplicates in my MySQL table

SELECT <column name>, COUNT( <column name> ) AS numOcc FROM <table> GROUP BY <column name> HAVING ( COUNT( <column name>) >1 ) This is an example of where you have duplicates in one column only.

orahome 19/09/2018 MySQL Code No Comments Read more

How to delete a primary key in MySQL

ALTER IGNORE TABLE <table> DROP PRIMARY KEY

orahome 19/09/2018 MySQL Code No Comments Read more

How to add a primary key index to a table and ignore and remove duplicates

Use the following SQL statement, put more than one column name in the brackets if you want more than one column as the primary key. ALTER IGNORE TABLE ADD PRIMARY KEY ()

orahome 19/09/2018 MySQL Code No Comments Read more

How to get the first word of a string using MySQL

There are two ways to do this using MID and LOCATE or by just using SUBSTRING_INDEX a. SELECT MID(,1,LOCATE(‘ ‘,)) FROM b. SELECT SUBSTRING_INDEX( , ‘ ‘, 1 ) FROM

orahome 19/09/2018 MySQL Code No Comments Read more

How can I capitalise each word in a MySQL text string without using PHP

This function below will capitalise each word in the string, in the same way that UCWORDS works in PHP. Just copy this function code and run it at the Mysql command line prompt. DELIMITER $$ DROP FUNCTION IF EXISTS `ICap`$$

orahome 19/09/2018 MySQL Code No Comments Read more

How to set text to have a Capital letter and then lowercase letters

In PHP we would use UCFIRST, so how do we do this in MySQL? SELECT CONCAT(UPPER(SUBSTRING(firstName, 1, 1)), LOWER(SUBSTRING(firstName FROM 2))) AS properFirstName You could also create your own MySQL function of this and then just call it, instead of

orahome 19/09/2018 MySQL Code No Comments Read more

How to display database records which are so many days old

Have a date field in your table which includes the date the record was inserted, try a TIMESTAMP data type, for our example our field is called ‘DATE_ADDED’ and then use the DATEDIFF MySQL function. Then run the following type

orahome 19/09/2018 MySQL Code No Comments Read more

How to select a random set of records using MySQL

ORDER BY RAND() combined with LIMIT is useful for selecting a random sample of a set of rows: SELECT * FROM <tablename> ORDER BY RAND() LIMIT 1000; Note that RAND() in a WHERE clause is re-evaluated every time the WHERE

orahome 19/09/2018 MySQL Code No Comments Read more
  • « Previous

Recent Posts

  • Plesk Upgrade 18.0.37 Fails with Grafana No More Mirrors Error
  • Microsoft Access Make Table Union Query Failing
  • Find the size of directories
  • How to Solve IP address conflict on Unix or Windows
  • Delete files older than 30 days in Linux

Categories

  • Access Functions
  • Affiliate Marketing
  • Articles
  • Book Reviews
    • MySQL Book Reviews
    • Oracle Book Reviews
    • Other Book Reviews
    • PHP Book Reviews
    • Web Marketing Book Reviews
  • Computer Book Releases
  • Computer Magazines
  • Computer Products
  • CSS Tips
  • Excel Functions
  • Javascript Code
  • Microsoft Access
  • MySQL Code
  • Oracle Built-in SQL Functions
  • Oracle DBA
  • Oracle Error Codes
    • EXP Error Codes
    • IMP Error Codes
    • ORA Error Codes
    • PLS Error Codes
  • Oracle Forms
  • Oracle Functions
  • Oracle Procedures
  • Oracle SQL
  • PHP Code
  • SEO Tips
  • Unix Code
  • Video Editing
  • Web Hosting

Archives

  • July 2021
  • March 2021
  • November 2020
  • August 2020
  • June 2020
  • May 2020
  • March 2020
  • March 2019
  • September 2018

Tag Cloud

059652708X 0596100892 0596101058 0596528000 book review computer magazine exp-00079 error code IMP-00066 mysql stored procedure programming ora-00229 error code ORA-00325 ora-00957 error code ORA-01046 ora-01226 error code ORA-01317 ora-01559 error code ORA-01646 ora-01722 ora-01747 error code ORA-01844 ora-02028 error code ORA-02141 ora-02318 error code ORA-02427 ora-02818 error code ORA-03206 ora-06032 error code ORA-06314 ora-06756 error code oracle error ora-00083 oracle error ora-00447 oracle error ora-01141 oracle error ora-01471 oracle error ora-01942 oracle error ora-02233 oracle error ora-02723 oracle error ora-04033 oracle error ora-06544 oracle error pls-00356 oracle pl/sql programming oracle set PLS-00220 pls-00451 error code PLS-00566 windows vista the definitive guide

Amazon Offers

Categories

  • Oracle SQL
  • Unix Code
  • MySQL Code
  • Oracle Functions
  • PHP Code
  • Oracle DBA
  • Oracle Procedures
  • Oracle Forms
  • ORA Error Codes
  • Computer Magazines

Pages

  • ASCII Table Lookup
  • Computer Book Reviews
  • New Computer Books
  • Oracle Database 10g
  • Oracle Employers
  • Oracle Forms
  • Oracle Jobsites
  • Oracle Reports
  • Oracle White Papers
  • Top 10 Javascript Books
  • Top 10 MySQL Computer Books
  • Top 10 Oracle Computer Books
  • Top 10 PHP Computer Books
  • Top 10 Raspberry Pi Books
  • Top 10 SEO and Internet Marketing Books
  • Unix Commands Cheat Sheet
Copyright © 2022 Oracle Home. All rights reserved. Theme Spacious by ThemeGrill. Powered by: WordPress.
  • Sitemap
  • Contact us
  • Privacy Policy