Welcome to WebmasterWorld Guest from 54.167.83.224

Forum Moderators: open

Message Too Old, No Replies

Help with ORDER BY statement

     
3:05 am on Jun 18, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 7, 2004
posts:88
votes: 0


For some reason the ORDER BY clause sort mode is case sensitive, that is, it "sorts" uppercase fields firts and lower case fields at the end.

Is there some way to specify a case insensitive sorting? Thanks!

6:24 am on June 18, 2007 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10544
votes: 8


you didn't really state which database or field type you are using, but in general you can try folding all column values to one case such as:
SELECT text_column FROM some_table ORDER BY UPPER(text_column)
1:56 pm on June 18, 2007 (gmt 0)

Preferred Member

5+ Year Member

joined:July 31, 2006
posts:629
votes: 0


This can be very slow on big tables because mysql will have to loop through each record uppercasing it. In this case you may consider saving uppercased values in separate indexed field and use it in where clause.

But above suggestions should be ok if table has not much data.

9:17 pm on June 18, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 7, 2004
posts:88
votes: 0


Thanks, I think that should work because table won´t be big initially, abnd the default sort mode will be date instead of name.