The ORDER BY clause allows to retrieve the rows of a result set in a specified order. It is good programming style to use an ORDER BY clause only if the database can cheaply do the sorting using a suitable index.
Sorting NULL values in a result set is database-dependent.
More information: Open SQL Database Dependencies
<order by clause> ::= |
<display name> is the name of a column in the result set. Ordering with respect to undefined <display name>s is not possible as this column cannot be named in a <sort specification>.
If a <display name> is ambiguous (that is, the same name is used in different <as clause>'s in the same statement) it cannot be used in a <sort specification>.
SELECT employee_name, salary AS sal |
ORDER BY Clause. This query selects the name and the salary of all employees. The result set is sorted descending by the salary.