Performing MySQL query with case sensitivity

Let us take note of the following example data.

WEBSITE_NAME
dev-notes.com
Dev-Notes.com
DEV-NOTES.com

Note that the first row is in all lower case, the second in proper case, and the third contains all capitalized letters. If we run a normal MySQL select statement to search for “dev-notes” such as the below, the system will return all three records.

/* Standard query; not case sensitive */
select * from mytable where website_name='dev-notes.com';

To get around it, simply use the “binary” keyword before the column name, shown in the example below.

/* Case sensitive query */
select * from mytable where binary website_name='dev-notes.com';

The query above will only return the first record, which is the one that contains all lower case letters.

Leave a Reply

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