HP 3000 Manuals

The ORDER BY Clause [ ALLBASE/Turbo CONNECT Administrator's Guide ] MPE/iX 5.0 Documentation


ALLBASE/Turbo CONNECT Administrator's Guide

The ORDER BY Clause 

The ORDER BY clause sorts the retrieved rows and orders them by the
specified column(s) in ascending or descending order.  If you want more
than one column sorted, list the major column first.  There are two ways
to specify the columns you want to order:

 *  By column name.
 *  By location of the column(s) in the select list.

If you are ordering by a column that is derived from an expression other
than a column name, you must specify it by number.

In the example below, the data is ordered by the aggregate function
column, which is the second column, and therefore a 2 is specified in the
ORDER BY clause.  By default, sorted columns are displayed in ascending
order.  However, in this case, descending is specified.
__________________________________________________________________________________
|                                                                                |
|     isql=> SELECT PartNumber, MIN (UnitPrice)                                  |
|     > FROM PurchDB.SupplyPrice                                                 |
|     > GROUP BY PartNumber                                                      |
|     > HAVING MIN (UnitPrice) <400.00                                           |
|     > ORDER BY 2 DESC;                                                         |
|                                                                                |
|     SELECT PartNumber, MIN (UnitPrice) FROM PurchDB.SupplyPrice                |
|     GROUP BY PartNu...                                                         |
|     ----------------+------------------                                        |
|     PARTNUMBER      |(EXPR)                                                    |
|     ----------------+------------------                                        |
|     1423-M-01       |            335.00                                        |
|     1233-MU-01      |            285.00                                        |
|     1723-AD-01      |            230.00                                        |
|     1733-AD-01      |            225.00                                        |
|     1153-P-01       |            200.00                                        |
|     1523-K-01       |            195.00                                        |
|     1333-D-01       |            195.00                                        |
|     1323-D-01       |            190.00                                        |
|     1133-P-01       |            180.00                                        |
|     1143-P-01       |            175.00                                        |
|     1243-MU-01      |             95.00                                        |
|     1223-MU-01      |             75.00                                        |
|     1923-PA-01      |             70.00                                        |
|                                                                                |
|     ---------------------------------------------------------------------------|
|     Number of rows selected is 13                                              |
|     U[p], d[own], l[eft], r[ight], t[op], b[ottom], pr[int]                    |
|     <n>, or e[nd] > end                                                        |
__________________________________________________________________________________


NOTE The more columns you choose to ORDER BY, the slower the query.


MPE/iX 5.0 Documentation