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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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' Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.