To sort the result set in ascending or descending order, use the ORDER BY keyword. By default, the ORDER BY keyword organises the records in ascending order. Use the DESC keyword to sort the records in descending order.
The ORDER BY clause is used to arrange entries in ascending or descending order on one or more columns. If the query contains them, the ORDER BY clause must occur after the WHERE, GROUP BY, and HAVING clauses.
A SQL SELECT query with the ORDER BY clause returns a result set with the rows sorted by the values of one or more columns.
SELECT name, credit limit FROM customers ORDER BY 2 DESC, 1; The name column is positioned 1 while the credit limit column is positioned 2. These column positions were utilised in the ORDER BY clause to tell Oracle to sort the data.
The WHERE clause can be used with or without the ORDER BY declaration.