Page 1 of 1

mysql_query and LIKE '[a-z]%' not working?

Posted: Wed Nov 24, 2010 9:28 pm
by chewedtoothpicks
heres the line:

Code: Select all

$query = mysql_query("SELECT * FROM vendors WHERE name LIKE '[a-m]%' ORDER BY name");
the query should return all names starting with characters a-m and sort in asc order right? But for some reason I get no records returned.

If I change [a-m]% to just a% it works for all a records, so it's an issue with using range matching... I thought this was a valid sql matching format?

is it a problem with mysql_query() in php?

Re: mysql_query and LIKE '[a-z]%' not working?

Posted: Wed Nov 24, 2010 11:30 pm
by McInfo
Use REGEXP in place of LIKE.

Code: Select all

SELECT * FROM vendors WHERE name REGEXP '^[a-m]' ORDER BY name