ORDER BY clause ORDER BY clause

The ORDER BY clause is an optional element of a . An ORDER BY clause allows you to specify the order in which rows appear in the ResultSet.

Syntax ORDER BY { | ColumnPosition } [ ASC | DESC ] [ , | ColumnPosition [ ASC | DESC ] ] *

ColumnPosition is an integer that identifies the number of the column in the SelectItem in the underlying Query of the . ColumnPosition must be greater than 0 and not greater than the number of columns in the result table. In other words, if you want to order by a column, that column must be in the select list.

refers to the names visible from the SelectItems in the underlying query of the . An order by column does not need to be in the select list.

ASCimplied in ORDER BY clauseDESCoptional element of ORDER BY clauseASC specifies that the results should be returned in ascending order; DESC specifies that the results should be returned in descending order. If the order is not specified, ASC is the default.

ORDER BY clauseaffecting cursorsAn ORDER BY clause prevents a SELECT statement from being an updatable cursor. (For more information, see .)

For example, if an INTEGER column contains integers, NULL is considered greater than 1 for purposes of sorting. In other words, NULL values are sorted high.

-- order by the correlation name NATION SELECT CITY_NAME, COUNTRY AS NATION FROM CITIES ORDER BY NATION