MySQL case sensitive query

Michael Liao picture Michael Liao · Oct 22, 2011 · Viewed 97.9k times · Source

This has been asked on this site before but I couldn't find a sufficient answer. If I'm doing a query like:

Select Seller from Table where Location = 'San Jose'

How can I make it return only Sellers with Location 'San Jose' instead of 'san jose' or something else?

Answer

James mason picture James mason · Oct 22, 2011

MySQL queries are not case-sensitive by default. Following is a simple query that is looking for 'value'. However it will return 'VALUE', 'value', 'VaLuE', etc…

SELECT * FROM `table` WHERE `column` = 'value'

The good news is that if you need to make a case-sensitive query, it is very easy to do using the BINARY operator, which forces a byte by byte comparison:

SELECT * FROM `table` WHERE BINARY `column` = 'value'