Page 1 of 1

SOLVED: mysql compare case-sensitive

Posted: Sat Aug 27, 2016 2:46 pm
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%'

Re: mysql compare case-sensitive

Posted: Sat Aug 27, 2016 3:51 pm
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]';

Re: mysql compare case-sensitive

Posted: Wed Sep 07, 2016 5:17 pm
by mister_v
Thanks,
that solved it for me.