faqts : Computers : Databases : MySQL : Language and Syntax : Queries : Order By

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

73 of 77 people (95%) answered Yes
Recently 10 of 10 people (100%) answered Yes

Entry

How can I reverse the sort order when using ORDER BY?
What are the ASC and DESC keywords for?

Jan 23rd, 2000 22:18
Nathan Wallace, Coke, Joshua Chamas


This query will return the rows from oldest to youngest when ordered by
the add time:

    SELECT * FROM links ORDER BY add_time;

To return the rows in the opposite sort order (youngest to oldest) use
the DESC (descending) keyword:

    SELECT * FROM links ORDER BY add_time DESC;

The default ordering is ASC (ascending).  So you can add the ASC keyword
without changing the results.  These commands are equivalent:

    SELECT * FROM links ORDER BY add_time;
    SELECT * FROM links ORDER BY add_time ASC;