MySQL: Perform Case Sensitive string comparison

In this post, I am providing a small demonstration to perform case sensitive string comparison with MySQL.

For example, if you are searching string with LIKE ‘a%’, also you get all records of LIKE ‘A%’ because of case insensitive.
By default, string comparisons are case insensitive because strings are nonbinary. For the case sensitive comparison, we should use binary collation.

If you require to perform all string comparison operations with Case Sensitive, you can use this COLLATION latin1_bin.
You can visit this article about, How to change default COLLATION in MySQL.

The String Case Sensitive Comparison using LIKE BINARY:

You can also perform string case sensitive comparison using LIKE BINARY operator.
Generally, we require this kind of requirement during password comparison.

Below is a full demonstration of this:

First, create sample table and data,

Execute below three queries and check the result:

Using normal LIKE you will get Case insensitive result and using LIKE BINARY you will get Case sensitive result.

Anvesh Patel

Leave a Reply

1 Comment on "MySQL: Perform Case Sensitive string comparison"

Notify of
Sort by:   newest | oldest | most voted

Hi Patel..thanks for share really I like your post keep in touch from Indonesia.