Progress
SQL-92
Guide and Reference


ORDER BY Clause

Allows ordering of the rows selected by the SELECT statement. Unless an ORDER BY clause is specified, the rows of the result set might be returned in an unpredictable order as determined by the access paths chosen and other decisions made by the query optimizer. The decisions made will be affected by the statistics generated from table and index data examined by the UPDATE STATISTICS command.

SYNTAX

ORDER BY { expr | posn } [ ASC | DESC ] 
  [ , { expr | posn } [ ASC | DESC ] , ... ] 

expr

Expression of one or more columns of the tables specified in the FROM clause of the SELECT statement.

posn

Integer column position of the columns selected by the SELECT statement.

ASC | DESC

Indicates whether to order by ascending order (ASC) or descending order. The default is ASC.

EXAMPLES

-- Produce a list of customers sorted by last_name. 
SELECT last_name, street, city, state, zip 
     FROM customer 
     ORDER BY last_name ; 
-- Produce a merged list of customers and suppliers sorted by last_name. 
SELECT last_name, street, state, zip 
     FROM customer 
     UNION 
     SELECT last_name, street, state, zip 
     FROM supplier 
     ORDER BY 1 ;  

NOTES


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095