Sorting record by alphabetic follow by number in one column

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
gnel2000
Forum Newbie
Posts: 16
Joined: Tue Jul 26, 2005 10:41 pm

Sorting record by alphabetic follow by number in one column

Post by gnel2000 »

hi there,

I have a column which contain numbers and alphabets, as i know mysql will sort the numbers first then follow by alphabet. I would like to sort the records by alphabetic then follow by numbers in ascending, can this be done in the query?
duk
Forum Contributor
Posts: 199
Joined: Wed May 19, 2004 8:45 am
Location: London

Post by duk »

ORDER bY ASC

have you try ??? not sure if works as you want...
gnel2000
Forum Newbie
Posts: 16
Joined: Tue Jul 26, 2005 10:41 pm

Post by gnel2000 »

hm, not really...

let said i have the following record:

abc
123
567
456
def

if i use ASC, it will sorted in this way:
123
456
567

but i want it to be like this:
abc
def
123
456
567

any idea?
printf
Forum Contributor
Posts: 173
Joined: Wed Jan 12, 2005 5:24 pm

Post by printf »

Code: Select all

SELECT my_column FROM my_table ORDER BY my_column+0, my_column;

reverse the ORDER to do it the other way around


pif
gnel2000
Forum Newbie
Posts: 16
Joined: Tue Jul 26, 2005 10:41 pm

Post by gnel2000 »

thanks printf , is working fine.

Thanks a lot.
Post Reply