I want case sensitive search in SQL query. But by default, MySQL does not consider the case of the strings.
Any idea on how to do a case sensitive search in SQL query?
case sensitiveMySQLselect
I want case sensitive search in SQL query. But by default, MySQL does not consider the case of the strings.
Any idea on how to do a case sensitive search in SQL query?
Best Answer
This is not quite true. Whenever you
create database
in MySQL, the database/schema has a character set and a collation. Each character set has a default collation; see here for more information.The default collation for character set
latin1
, which islatin1_swedish_ci
, happens to be case-insensitive.You can choose a case-sensitive collation, for example
latin1_general_cs
(MySQL grammar):This has an effect on things like grouping and equality. For example,
In a case-sensitive database, we get:
While in a case-insensitive database, we get:
Note that you can also change the collation from within a query. For example, in the case-sensitive database, I can do