esport Posted July 18, 2006 Share Posted July 18, 2006 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? ThanksDaniel Link to comment https://forums.phpfreaks.com/topic/14896-mysql-query-a-z/ Share on other sites More sharing options...
AndyB Posted July 18, 2006 Share Posted July 18, 2006 SELECT * FROM tablename WHERE left(somefieldname,1) = 'A' ... for example Link to comment https://forums.phpfreaks.com/topic/14896-mysql-query-a-z/#findComment-59699 Share on other sites More sharing options...
esport Posted July 18, 2006 Author Share Posted July 18, 2006 Thanks mate, works great. I guess its not case sensitive?Daniel Link to comment https://forums.phpfreaks.com/topic/14896-mysql-query-a-z/#findComment-59713 Share on other sites More sharing options...
AndyB Posted July 18, 2006 Share Posted July 18, 2006 [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' Link to comment https://forums.phpfreaks.com/topic/14896-mysql-query-a-z/#findComment-59735 Share on other sites More sharing options...
fenway Posted July 18, 2006 Share Posted July 18, 2006 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. Link to comment https://forums.phpfreaks.com/topic/14896-mysql-query-a-z/#findComment-59830 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.