ORDER BY

As part of the SQL SELECT statement, you can specify the sequence in which selected rows are displayed. You can also eliminate duplicate rows in a selection.

ORDER BY specifies the order in which rows appear in a report. If you use ORDER BY, it must be the last clause in the entire statement. Any columns named after ORDER BY must also be named after SELECT.

The format of the ORDER BY clause is:

  ORDER BY columnname DESC     (for descending order)

If you do not specify an ordering sequence, ascending order is assumed.

The following report shows rows in ascending order.

This query:

SELECT NAME, JOB, YEARS
FROM Q.STAFF
WHERE DEPT = 84
ORDER BY JOB

Produces this report:

NAME      JOB    YEARS
--------- -----  -----
GAFNEY    CLERK      5
QUILL     MGR       10
DAVIS     SALES      5
EDWARDS   SALES      7
[ Previous Page | Next Page | Contents | Index ]