24.4.3 ORDER BY Clause
The rows in the result of a query can be sorted into ascending or descending order by using the optional ORDER BY clause. The basic form of a query with an ORDER BY
clause is
SELECT columnName1, columnName2, ... FROM tableName ORDER BY column ASCSELECT columnName1, columnName2, ... FROM tableName ORDER BY column DESC
where ASC
specifies ascending order (lowest to highest), DESC
specifies descending order (highest to lowest) and column specifies the column on which the sort is based. For example, to obtain the list of authors in ascending order by last name (Fig. 24.15), use the query
SELECT AuthorID, FirstName, LastName FROM Authors ORDER BY LastName
Get Java™ How To Program (Early Objects), Tenth 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.