Friday, March 27, 2009

MySQL - Is select query case sensitive?


Select query in MySQL can be either case sensitive or case insensitive by default.

It depends on CHARSET defined while creating the table. Binary chartset(e.g utf8) will make select query case sensitive by default. But anyway we can force the select query case insensitive by using UCASE in the query.

e.g select * from companys where ucase(name)=ucase('QualityPoint')
More Articles...

2 comments:

Anonymous said...

Actually, it depends on the collation of the column or expression, not the character set. Collations are related to character sets, and binary collations are case sensitive, as are columns of the (VAR)BINARY data type.

For example:

mysql> select "equals" = "EQUALS";
+---------------------+
| "equals" = "EQUALS" |
+---------------------+
| 1 |
+---------------------+
1 row in set (0.00 sec)

versus

mysql> select "equals" = "EQUALS" collate latin1_bin;
+----------------------------------------+
| "equals" = "EQUALS" collate latin1_bin |
+----------------------------------------+
| 0 |
+----------------------------------------+
1 row in set (0.35 sec)

or

mysql> select "equals" = cast("EQUALS" as BINARY);
+-------------------------------------+
| "equals" = cast("EQUALS" as BINARY) |
+-------------------------------------+
| 0 |
+-------------------------------------+
1 row in set (0.00 sec)

Rajamanickam Antonimuthu said...

Justin Swanhart,

Thanks for your explanation.

Search This Blog