ORDER BY Clause

Specify the order in which rows appear in the ResultSet.

Syntax

ORDER BY { column-name | ColumnPosition | Expression }
    [ ASC | DESC ]
    [ , column-name | ColumnPosition | Expression
        [ ASC | DESC ] ] * 

Description

The ORDER BY clause is an optional element of a SELECT statement. An ORDER BY clause allows you to specify the order in which rows appear in the ResultSet.
Note: You cannot use the ORDER BY clause in a query used to create a view. See CREATE VIEW.

SQLFire does not support using ORDER BY on a column of datatype BLOB, CLOB, or LONG VARCHAR FOR BIT DATA.

Refers to the names visible from the SelectItems in the underlying query of the SELECT statement. The column-Name that you specify in the ORDER BY clause does not need to be the SELECT list.

An integer that identifies the number of the column in the SelectItems in the underlying query of the SELECT statement. 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 specified in the SELECT list.

A sort key expression, such as numeric, string, and datetime expressions. Expression can also be a row value expression such as a scalar subquery or case expression.

Specifies that the results should be returned in ascending order. If the order is not specified, ASC is the default.

Specifies that the results should be returned in descending order.

Note: If SELECT DISTINCT is specified or if the SELECT statement contains a GROUP BY clause, the ORDER BY columns must be in the SELECT list.
Note: An ORDER BY clause prevents a SELECT statement from being an updatable cursor.