Chapter 8
The ORDER BY
Clause
In this chapter, we’ll look at the ORDER BY
clause, the last of the clauses of the SELECT
SQL statement.[6] Not only is ORDER BY
the last clause in the syntax, it’s also the last clause in the execution sequence. Fortunately, ORDER BY
is a really simple clause, so let’s jump right in.
The purpose of the ORDER BY
clause is to ensure that the result set produced by the query is returned in the specified sequence. Simply, ORDER BY
sorts the results. (Personally, I think SORT BY
might have been a better keyword, but it’s ORDER BY
and we just have to live with it.)
ORDER BY
Syntax
Like the SELECT
clause, the ORDER BY
clause has very simple syntax:
ORDER BY column [ASC | DESC] [, column [ASC | DESC]] …
Get Simply SQL 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.