Search the Site

Sponsors

bottom corner

Performing MySQL query with case sensitivity

By default, MySQL queries are not case sensitive. By using the "binary" keyword, we can easily match by specific casing when necessary.

This page is filed under keyword(s): mysql.

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.

Did you find this page useful? Please consider browsing other articles or subscribing to the RSS feed to keep up with latest.

This page is filed under keyword(s): mysql.
Author: C. Peter Chen
Last updated: 13 Mar 2009

bottom corner