Wednesday, 25 July 2018

MySQL: Perform Case Sensitive string comparison

In this post, I am sharing a small demonstration on how to perform case-sensitive string comparison in MySQL.
For example, if you are searching string with LIKE ‘a%’, also you get all records of LIKE ‘A%’ – the reason is the case-insensitive comparison.
By default, string comparisons are case insensitive because strings are non-binary. For the case-sensitive comparison, we should use binary collation.
If you need case-sensitive string comparison, you should use this COLLATION latin1_bin.
The String Case Sensitive Comparison using LIKE BINARY:
You can also perform string case-sensitive comparison using LIKE BINARY operator.
Generally, we need for password comparison.
Below is a full demonstration on this:
Create a 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 the Case sensitive result.

0 comments:

Post a Comment