Thursday, September 15, 2011

Case-sensitive compares in MySQL

Sometimes you want to do a case-sensitive compare even though the collation on the column is case-insensitive.

The solution is to use a binary collation, like this:

SELECT country FROM purchases
WHERE country COLLATE utf8_bin = 'us';

However, be aware that this also affects the handling of accents, so that "e" and "ë" will not compare as equal.

No comments:

Post a Comment