Sort key

You can specify the order of selected rows by using sort keys that you identify in the ORDER BY clause.

A sort key can be a column name, an integer that represents the number of a column in the result table, or an expression. You can identify more than one column.

You can list the rows in ascending or descending order. Null values are included last in an ascending sort and first in a descending sort.

Db2 sorts strings in the collating sequence that is associated with the encoding scheme of the table. Db2 sorts numbers algebraically and sorts datetime values chronologically.