Page 1 of 1

MySQL Select Based on first letter

Posted: Tue Jun 17, 2003 7:25 am
by ILoveJackDaniels
I've got a database of users and want to create a members list. I've set it up so that a member can click on, say, "A" for all usernames beginning with an "A". However, I have quite a lot of members whose names begin with a digit or non-alphanumeric character. How do I form a select to grab all data where a username's first character is not alphanumeric?

My current query for selecting names starting with "A" reads something like this:

Code: Select all

SELECT * FROM users WHERE username like "A%"

Posted: Tue Jun 17, 2003 8:20 am
by releasedj
A little more tricky:

Code: Select all

SELECT * FROM users WHERE SUBSTRING(username,1,1) NOT REGEXP "їa-zA-Z]"
Not tested, but I think it should work.

Kelvin

Posted: Tue Jun 17, 2003 10:27 am
by ILoveJackDaniels
Spot on, releasedj, thankyou.