MySQL/SQL gurus: can GROUP BY be case sensitive?

aceO07

Diamond Member
Nov 6, 2000
4,491
0
76
Is it possible to have GROUP BY be case sensitive? I noticed that it will group a string that has the same characters together, even if the characters have are not the same case.

For example "100Cars" will get grouped with "100CARS". Is this standard for SQL? Is it possible to not group the 2 together when using GROUP BY?
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
SQL is generally not case-sensitive. If you have to differentiate between two columns with the same name, do something like this:
select 100cars as 100casr2 from carstuff;
 

aceO07

Diamond Member
Nov 6, 2000
4,491
0
76
Originally posted by: notfred
SQL is generally not case-sensitive. If you have to differentiate between two columns with the same name, do something like this:
select 100cars as 100casr2 from carstuff;

I'm not referring to 2 columns. It's 2 values in the same column.

[Misc]
100Cars
100CARS
200Cars
300Cars

When I do a GROUPY BY Misc, it will group the 100Cars and 100CARS into 1 group.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Try selecting the Misc column as a binary field.

SELECT, col1, col2, CAST(Misc as BINARY) FROM table GROUP BY Misc;
 

jjones

Lifer
Oct 9, 2001
15,424
2
0
You can force case-sensitive sorting using BINARY (ORDER BY BINARY col_name) but I don't know if that works for GROUP BY. Never hurts to try.

lol, notfred beat me to it. :D
 

Jack Ryan

Golden Member
Jun 11, 2004
1,353
0
0
Originally posted by: aceO07
Is it possible to have GROUP BY be case sensitive? I noticed that it will group a string that has the same characters together, even if the characters have are not the same case.

For example "100Cars" will get grouped with "100CARS". Is this standard for SQL? Is it possible to not group the 2 together when using GROUP BY?

I'll have to go with something is wrong here. Those should NOT be grouped together.