Sort keys with multiple columns

You can specify more than one column name in the ORDER BY clause to order rows by the values in more than one column.

When several rows have the same first ordering column value, those rows are in order of the second column that you identify in the ORDER BY clause, and then on the third ordering column, and so on.

Example

Begin general-use programming interface information.

Consider this query:

SELECT JOB, EDL, LASTNAME
  FROM EMP
  WHERE DEPT = 'A00'
  ORDER BY JOB, EDL;

The result table looks like the following example:

JOB     EDL     LASTNAME
====    ===     ==========
PRES    18      HAAS
SLS     14      CONNOR
SLS     18      HEMMINGER
End general-use programming interface information.