November 17, 2009

MySQL REGEXP: where first letter is numeric

Category: mysql, Tags: , , khadlock at 11:58 am

Get MySQL results where the first letter is numeric:

SELECTFROM table WHERE (LEFT(columnname,1) REGEXP '[0-9]')

Or get MySQL results where the first letter is alpha:

SELECTFROM table WHERE (LEFT(columnname,1) REGEXP '[a-z]')
Bookmark and Share

 

November 15, 2009

Using the IN statement to retrieve multiple results from a subquery

Category: mysql, Tags: , khadlock at 8:20 pm

Use the IN statement to retrieve multiple results from a subquery.

SELECT * FROM table WHERE id IN ( SELECT DISTINCT id FROM table WHERE id=1 )
Bookmark and Share

 

November 14, 2009

Get MySQL results by first letter

Category: mysql, Tags: , khadlock at 7:20 pm

The following SQL selects all the rows where columnname starts with the letter A, switch the letter or make it a variable and get the results you need.

SELECT * FROM table WHERE columnname LIKE 'A%'
Bookmark and Share