Coders' Corner Search:
General :: Databases :: mysql
General information about mysql - how to get around the differences between version 3.33 an 4, how to do stuff that you think you need a nested query for etc.

Articles:


Featured Article

How to compare strings in mysql case sensitive

Question:

My application includes a query where I want to list all products with a name that starts in upper case. The SQL looked like

.. where prod_name >= 'A' and prod_name <= 'Z';

Turns out this included lowercase products. A further investigation shows

select 'A' = 'a';

returns TRUE (1). How can I make mysql case sensitive?

Answer:

Instead of using the = operator, you may want to use LIKE or LIKE BINARY

// this returns 1 (true)
select 'A' like 'a'
 
 // this returns 0 (false)
select 'A' like binary 'a'