mghhgm mghhgm - 1 month ago 7
MySQL Question

MySQL select by difference between lowercase and uppercase characters

I have table like this:

Table name: hash_table
----------------
id hash
----------------
1 abc
2 aBc
3 abC
4 AbC
5 ABc
----------------


There is difference between lowercase and uppercase characters. For example
abc
unequal
aBc
.

In this query, return all rows:

SELECT * FROM `hash_table` WHERE `hash` = "abc"


By search in stackoverflow, some answers talk about
UPPER
,
LOWER
and
UCASE
use in select query but they return all rows.

Is there a way to return only correct row?

Answer

String comparision could ve performed in sql in two distinct way ..binary and not binary .. If you don't cast binary .. the comparision is case insentive .. if you useing binary the comparision is done by byte and the is also case sensitive ..

try using

SELECT * FROM `hash_table` WHERE BINARY `hash` = BINARY "abc"
Comments