Order By clause
- Last Updated: July 25, 2025
- 1 minute read
- DataDirect Connectors
- ODBC
- Apache Cassandra 8.0
- Documentation
Purpose
The Order By clause specifies how the rows are to be sorted.
Syntax
ORDER BY sort_expression [DESC | ASC] [,...]
where:
- sort_expression
- is either the name of a column, a column alias, a SQL expression, or the positioned number of the column or expression in the select list to use.
The default is to perform
an ascending (ASC) sort.
Example
To sort by LAST_NAME and then by FIRST_NAME, you could use either of the following Select
statements:
SELECT EMP_ID, LAST_NAME, FIRST_NAME FROM EMP
ORDER BY LAST_NAME, FIRST_NAME
or
SELECT EMP_ID, LAST_NAME, FIRST_NAME FROM EMP
ORDER BY 2,3
In the second example, LAST_NAME is the
second item in the Select list, so ORDER BY 2,3 sorts by
LAST_NAME and then by FIRST_NAME.