Ordering and limiting results
The results of a query are not ordered by default. The order of the rows is not defined and may depend on their physical location on disk, the joining algorithm or on other factors. In many cases, it's required to sort the result set. This is done with the ORDER BY clause. The list of expressions whose values should be sorted is specified after the ORDER BY keyword. At the beginning, the records are sorted on the basis of the first expression of the ORDER BY list. If some rows have the same value for the first expression, they are sorted by the values of the second expression, and so on.
For each item of the ORDER BY list, it's possible to specify whether the order should be ascending or descending. This is done ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access