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.)


Like the SELECT clause, the ORDER BY clause has very simple syntax:

   column [ASC | DESC]
[, column [ASC | DESC]]

Get Simply SQL now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.