2. Sorting Query Results
Returning Query Results in a Specified Order
We want to order query result.
Sorting by Multiple Fields
We want to sort the rows from EMP first by DEPTNO ascending, then by SALARY descending.
Sorting by Substrings
We want to sort the results of a query by specific parts of a string. For example, we want to return employee names and jobs from table EMP and sort by the last two characters in the JOB field.
Sorting Mixed Alphanumeric Data
Use the functions REPLACE and TRANSLATE to modify the string for sorting.
Dealing with Nulls When Sorting
We want to sort results from EMP by COMM, but the field is nullable. We need a way to specify whether nulls should come last.
Sorting based on some specific data
We want to sort based on some conditional logic. For example, if JOB is SALESMAN, we want to sort on COMM; otherwise, we want to sort by SAL. Use a CASE expression in the ORDER BY clause.
Last updated
Was this helpful?