Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort by Multiple Fields in Different Directions?

Status
Not open for further replies.

Actorial

Programmer
Aug 23, 2006
38
US
Hi,

I'm wondering if I can sort by multiple categories in different directions. I tried this and it doesn't work:

Code:
SELECT * FROM table ORDER BY field1 DESC ORDER BY field2 ASC LIMIT 0,10

And it doesn't work, any advice?
 
nevermind, i solved my own prblem, just was missing commmas after each ASC or DESC!
 
you can't have two separate order by clauses in there of course, just the list of the columns and as you say separated by a comma.

Code:
select 
foo,
bar
from yourtable
order by foo asc, bar desc

and to save a few keystrokes ascending is the default so you don't have to note that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top