It can also be used in an INSERT statement or a CREATE VIEW statement.
An ORDER BY clause allows you to specify the order in which rows appear in the result set. In subqueries, the ORDER BY clause is meaningless unless it is accompanied by one or both of the result offset and fetch first clauses or in conjunction with the ROW_NUMBER function, since there is no guarantee that the order is retained in the outer result set. It is permissible to combine ORDER BY on the outer query with ORDER BY in subqueries.
ORDER BY { columnName | columnPosition | expression } [ ASC | DESC ] [ NULLS FIRST | NULLS LAST ] [ , columnName | columnPosition | expression [ ASC | DESC ] [ NULLS FIRST | NULLS LAST ] ]*
You can sort the result set by a correlation name, if the correlation name is specified in the select list. For example, to return from the CITIES database all of the entries in the CITY_NAME and COUNTRY columns, where the COUNTRY column has the correlation name NATION, you specify this SELECT statement:
SELECT CITY_NAME, COUNTRY AS NATION FROM CITIES ORDER BY NATION
SELECT name, salary, bonus FROM employee ORDER BY salary+bonusIn this example, the salary and bonus columns are DECIMAL data types.
SELECT i, len FROM measures ORDER BY sin(i)
SELECT * FROM t1 ORDER BY c1 DESC NULLS LAST