SOLVED: mysql compare case-sensitive

Post Reply
mister_v
Posts: 180
Joined: Thu Mar 04, 2010 9:19 pm

SOLVED: mysql compare case-sensitive

Post by mister_v »

The queries are case insensitive.
That is good for most cases.
But now I want a case sensitive search.
For example all names starting with a small 'a'

Code: Select all

SELECT name FROM table WHERE name LIKE 'a%'
Last edited by mister_v on Wed Sep 07, 2016 5:17 pm, edited 1 time in total.
chris
Site Admin
Posts: 182
Joined: Mon Jul 21, 2008 9:52 am

Re: mysql compare case-sensitive

Post by chris »

You can use binary to make it work:

Code: Select all

SELECT name FROM table WHERE name LIKE BINARY 'a%';
It converts to binary and then compares,
so It is not exactly case insensitive.
It will not match 'à' for example.

Binary also works with REGEXP

Code: Select all

SELECT name FROM table WHERE name REGEXP BINARY '^[a-z]';
mister_v
Posts: 180
Joined: Thu Mar 04, 2010 9:19 pm

Re: mysql compare case-sensitive

Post by mister_v »

Thanks,
that solved it for me.
Post Reply