Using QMF


Sorting the rows in a query

To specify the way you want to sort the rows, use the ORDER BY keyword. Follow ORDER BY with the name of the column, or columns, on which you want to sort the rows. QMF sorts the rows in ascending order unless you specify descending order.

For example, the following query displays the rows in ascending orders by job:

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

If you sort rows by more than one column, the first column is ordered first, the second column is ordered within the order of the first column, and so on.

This query displays the rows in ascending order by job, and orders the years within job in descending order.

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

+--------------------------------------------------------------------------------+
|   NAME         JOB   YEARS                                                     |
|   ---------  -----  ------                                                     |
|   GAFNEY     CLERK       5                                                     |
|   QUILL        MGR      10                                                     |
|   EDWARDS    SALES       7                                                     |
|   DAVIS      SALES       5                                                     |
+--------------------------------------------------------------------------------+


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]