Specifying Sort Direction

Data sorting is not limited to ascending sort orders (from A to Z). Although this is the default sort order, the ORDER BY clause can also be used to sort in descending order (from Z to A). To sort by descending order, the keyword DESC must be specified.

The following example sorts the products by price in descending order (most expensive first):

SELECT prod_id, prod_price, prod_name
FROM Products
ORDER BY prod_price DESC;
 prod_id prod_price prod_name ------- ---------- -------------------- BR03 11.9900 18 inch teddy bear RYL01 9.4900 King doll RYL02 9.4900 Queen doll BR02 8.9900 12 inch teddy bear BR01 5.9900 8 inch teddy bear RGAN01 4.9900 Raggedy Ann BNBG01 3.4900 Fish bean bag toy BNBG02 3.4900 Bird bean bag toy ...

Get Sams Teach Yourself SQL in 10 Minutes, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.