Skip to content

MySQL case-sensitive Search with LIKE

Advertisement

The LIKE statement is used for searching records with partial strings in MySQL. By default the query with LIKE matches case-insensitive recores. Means query will match both records in lowercase or uppercase.

For example, Search all records un colors table where name is start with “Gr”.

Mysql match all cases in LIKE

You can see the above query matches records with any cases.

But, sometimes you need to select case-sensitive data only. In that case, You need to cast the values as binary.

To do this add BINARY option with like statment and view the results:

Mysql case-sensitive LIKE query

You can see the result contains only those records, which matches extactly with case-sensitive. When we use BINARY, then mysql compare data byte-by-byte. Without BINARY it compares data character-by-character.

Rahul

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

Leave a Reply

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


Back to top