Previous Topic: ORDER BY ClauseNext Topic: Processing


Description

ORDER BY

Puts the rows of the result table in order by the values of the columns you identify. If you identify more than one column, the rows are ordered first by the values of the column you identify first, then by the values of the column you identify second, and so on. If you do not specify the ORDER BY clause, the rows of the result table have an arbitrary order.

colume-name

Each column-name specified must unambiguously identify a column of the result table. The sum of the lengths of the columns must be less than 32720. The column names must be separated by commas.

integer

The integer n identifies the nth column of the result table. Each integer specified must be greater than 0 and not greater than the number of columns in the result table. The integers must be separated by commas.

A named column can be identified by an integer or a column-name.

An unnamed column must be identified by an integer. A column is unnamed if it is derived from:

If the full-select statement includes a UNION operator, every column of the result table is unnamed.

ASC

Places the values of the column in ascending order. ASC is the default order.

DESC

Places the values of the column in descending order.

Ordering is performed in accordance with the comparison rules. The null value is higher than all other values. If your ordering specification does not determine a complete ordering, rows with duplicate values of the last identified column have an arbitrary order.