Case Sensitive string search on MySQL

Quick reference post to search string with case sensitivity.

MySQL String search is case-insensitive by default. Using BINARY on the WHERE clause forces MySQL to check its binary Collation which tries to match its character code rather than its string value; meaning “A != a” when using BINARY.

SELECT * FROM TABLE WHERE BINARY column = 'ABcdEFG';

The BINARY operator casts the string following it to a binary string. This is an easy way to force a comparison to be done byte by byte rather than character by character. BINARY also causes trailing spaces to be significant.

Reference: http://dev.mysql.com/doc/refman/5.0/en/charset-binary-op.html

Leave a Reply

Your email address will not be published. Required fields are marked *

*