Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding only strings starting with a number using MySQL LIKE

Tags:

mysql

How can I find strings in a table where the first character is a number?

I'm using MySQL LIKE as follows

SELECT   DISTINCT label_no_country
FROM     releases
WHERE    label_no_country LIKE '$letter%'  
ORDER BY label_no_country

where $letter is a letter between A-Z (depending on the input)

So if $letter == 'A' then it will show all entries where the first letter is A.

How can I run this query so that it will show records that start with numbers?

e.g.

1st record

cheers!

like image 815
Franco Avatar asked Nov 28 '22 02:11

Franco


1 Answers

You might want to use Regular Expressions:

SELECT DISTINCT label_no_country FROM releases 
WHERE label_no_country 
REGEXP '^[0-9]'

See MySQL docs for details.

like image 132
egrunin Avatar answered Dec 23 '22 10:12

egrunin