Skip to content
Advertisement

Mysql group by included the whitespace as same value

I have this table

and this value

I need to group by the data and count how many data that have same value, so i used group by and count

the result not what i expect because the data for ID 1,2,5, and 3 is counted as same value like below result

how could i make the result like expected result below so the value didn’t count as same value

see this fiddle for demo

Advertisement

Answer

This is just how MySQL does it by default, unless you use some specific collation. A typical workaround is to use binary:

Or, if you do want a regular string in the resultset rather than a binary string:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement