Jump to content

Archived

This topic is now archived and is closed to further replies.

esport

mysql query A-Z

Recommended Posts

Hi,
I'm trying to do query that matches the first character of a feild. Rather than selecting all rows from the table then doing an 'if' statement to filter out the rows you dont wont, is there a way doing a mysql query that only matches the first character?
Thanks

Daniel

Share this post


Link to post
Share on other sites
SELECT * FROM tablename WHERE left(somefieldname,1) = 'A' ... for example

Share this post


Link to post
Share on other sites
Thanks mate, works great. I guess its not case sensitive?

Daniel

Share this post


Link to post
Share on other sites
[quote author=esport link=topic=100939.msg398996#msg398996 date=1153183671]
Thanks mate, works great. I guess its not case sensitive?[/quote]

Correct. Did it need to be? If so, I *think* you need to modify the query to ... BINARY left(somefieldname,1) = 'your choice of case-sensitive letter'

Share this post


Link to post
Share on other sites
You can also use a simple REGEXP for this, though I've not done the performance comparisons... personally, I find REGEXs easier to read, but I spend all my time staring at Perl code, so I'm biased.  BTW, MySQL 4.1+ requires the use of a COLLATION to get the old binary attribute, AFAIK.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.