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

  • SQL Server OUTPUT Command
  • Direct Joins for UPDATE and DELETE in Oracle 23ai Database
  • GROUP BY Column Alias or Position in Oracle 23ai
  • SELECT without FROM DUAL in Oracle 23ai Database
  • IF EXISTS and IF NOT EXISTS in SQL in Oracle 23ai Database

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 23ai
  • 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
  • SQL Server
  • Unix Code
  • Video Editing
  • Web Hosting

Archives

  • March 2025
  • July 2024
  • March 2024
  • 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 case insensitive search oracle case insensitive search sql center data column sql centre data column sql compare strings oracle compare strings sql convert floating point numbers create varrays sql deleted oracle datafile difference between two dates drop all empty tables drop column from table oracle drop column in table drop column table sql employee service time sql limit objects created by user mysql stored procedure programming network windows xp to windows vista number types sql ora-01722 oracle 11g new features oracle 23ai oracle datafile oracle pl/sql programming oracle rename column table remove leading zeros remove zeros from string sql rename table column sql select last saturday in every month select random number set oracle select random numbers sql sql difference between dates sql time between dates start windows oracle website accessibility website screen readers windows oracle service windows vista windows vista the definitive guide windows xp

Amazon Offers

Categories

  • Oracle SQL
  • Unix Code
  • MySQL Code
  • Oracle Functions
  • PHP Code
  • Oracle DBA
  • Oracle Procedures
  • Oracle Forms
  • Oracle 23ai
  • 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 © 2025 Oracle Home. All rights reserved. Theme Spacious by ThemeGrill. Powered by: WordPress.
  • Sitemap
  • Contact us
  • Privacy Policy