ORDER BY Syntax

The general syntax for the SELECT statement ORDER BY clause looks like this:

SELECT select_list
FROM table_list
[WHERE conditions]
[ORDER BY order_by_list]

Like the SELECT list, the ORDER BY list can have one element or multiple elements. If there are multiple elements, they must be separated by commas. Each ORDER BY expression can be ascending (the default) or descending (DESC).

Here's a query that finds some information on business and psychology books:

SQL
 select title_id, pub_id, price * ytd_sales as Income, price from titles where type in ('business', 'psychology') title_id pub_id Income price ======== ====== ============== ========== BU1032 1389 122809.05 29.99 PS7777 0736 60014.64 17.99 PS3333 0736 122119.28 29.99 BU1111 ...

Get Practical SQL Handbook, The: Using SQL Variants, Fourth 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.