ORDER BY

This item is optional. It specifies the order in which the requested records are grouped. When ORDER BY is not specified, record transfer is not done according to a certain order.

Records are grouped according to the field specified first. Those records having the same value in each field specified first are grouped by the field specified second, and so on. Records containing null values are grouped after all records without null values have been grouped.

For example, you can specify:
DEPT,NAME,PHONE

In this case, records are first grouped according to DEPT. Then, the records having the same value for DEPT are grouped by NAME. The records with the same DEPT and NAME values are finally grouped by PHONE.

When a field name is specified in ORDER BY, it must also have been specified in SELECT, or SELECT* must have been specified.

Fields can be grouped in ascending or descending order. To do this, specify one blank after a field name then enter ASC or DESC. The default value is ASC. For example, specify:
DEPT DESC, NAME ASC

This indicates that the DEPT fields are to be grouped in descending order, after which the NAME fields are to be grouped in ascending (alphabetic) order.

Absolute values (ABS) can be specified for numeric fields. To do this, add a blank after a field name then enter ABS. For those fields having negative values, the negative signs are ignored and the absolute values are used.

The total length of the fields to be specified must not exceed 120 digits.