Page 1 of 1

ordering by 2 columns

Posted: Thu Jun 01, 2006 4:19 pm
by John Cartwright
I am doing a search where I need to search by 2 different columns..

`accounts`.`status` and `accounts`.`id`

Now status is an enum (paid, free, or expired) and id is autoincremented.. when I try to put both in them in the order by clause it will not work as expected, expected being

Code: Select all

paid 100
paid 82
paid 70

free 99
free 25
free 21
So in plain english, status paid comes up first (all I'm concerned about) and then it orders by descending Id's.. anyone know how I can accomplish this

Posted: Thu Jun 01, 2006 6:14 pm
by feyd
what's the result you're getting?

Posted: Thu Jun 01, 2006 7:38 pm
by Burrito

Code: Select all

order by status, id

Posted: Thu Jun 01, 2006 8:40 pm
by RobertGonzalez
Can you create a pseudo-field (concatenated field of status and id) to sort by? Or what about ORDER BY status DESC, ID DESC?