The ORDER clause specifies a sort sequence for a result table.
<order_clause> ::= ORDER BY <sort_spec>,...
<sort_spec> ::= <unsigned_integer> [ASC | DESC] | <expression> [ASC | DESC]
The sort columns specified in the order clause determine the sequence of the sort criteria.
A number n specified in the sorting specification (sort_spec) identifies the nth column in the result table. n must be less than or equal to the number of columns in the result table.
Scalable subqueries are not permissible in an ORDER clause.
ASC: the values are sorted in ascending order.
DESC: the values are sorted in descending order.
The default setting is ASC.
If a QUERY expression consists of more than one QUERY specification, sort specifications must be specified in the form <unsigned_integer> [ASC | DESC].
If a query specification was specified with DISTINCT, the total of the internal lengths of all sorting columns must not exceed 1016 characters; otherwise it can comprise 1020 characters.
Column names in the sort specifications must be columns in the tables of the FROM clause or a result_column_namein the selected columns of the QUERY specification.
If DISTINCT or a set function was used in a selected column, the sort specification must identify a column in the result table.
Values are compared in accordance with the rules for the comparison predicate. For sorting purposes, NULL values are greater than non-NULL values, and special NULL values are greater than non-NULL values but less than NULL values.
See also: