Databases InterBase (29) MS-SQL (5) mysql (37) Oracle (1)
Exchange Links About this site Links to us 
|
How to compare strings in mysql case sensitive
6 comments. Current rating: (2 votes). Leave comments and/ or rate it.
Question: My application includes a query where I want to list all products with a name that starts in upper case. The SQL looked like
.. where prod_name >= 'A' and prod_name <= 'Z';
Turns out this included lowercase products. A further investigation shows
select 'A' = 'a';
returns TRUE (1). How can I make mysql case sensitive?
Answer: Instead of using the = operator, you may want to use LIKE or LIKE BINARY
 | |  | | select 'A' like 'a'
select 'A' like binary 'a'
| |  | |  |
Comments:
|
anonymous from United States
|
 |
|
|
Nice and simple article. I was looking for a way to do this that was simple, and you're shown just that. Keep it up!!
|
|
anonymous from France
|
|
|
|
Found this useful until I realized that some of the strings I want to compare contain '_' and '%' characters that LIKE will interpret as wildcards.
I then tried SELECT BINARY A = B, that solved my problem.
|
|
anonymous from Portugal
|
|
|
|
Well Done thats it.
|
|
anonymous
|
 |
|
|
Thank u gr8 work man!!!!!
|
2009-08-24, 09:45:23 (updated: 2009-08-24, 09:46:07) |
anonymous from Canada
|
|
|
|
Thank u gr8 - I had a login that was redirecting to another directory and the case had to be the same as it.
|
|
anonymous from Indonesia
|
|
|
|
wonderful trick, thanks.
|
|