The ORDER clause (order_clause) specifies a sort sequence for a result table.
<order_clause> ::= ORDER BY <sort_spec>,...
SQL Tutorial, Selecting and Arranging Rows
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.
<sort_spec> ::= <unsigned_integer> [ASC | DESC]
| <column_spec> [ASC | DESC]
As the column specification column_spec in this case, you can either use a reference name reference_name or a column name column_name from the list of selected columns of the first QUERY specification.
Scalable subqueries are not permissible in an ORDER clause.
The default setting is ASC.
? ASC: the values are sorted in ascending order.
? DESC: the values are sorted in descending order.
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.
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.