- 
                Notifications
    
You must be signed in to change notification settings  - Fork 435
 
ORDER BY clause
        Rene Saarsoo edited this page Jul 17, 2022 
        ·
        9 revisions
      
    SQL standard defines the following syntax for ordering:
ORDER BY {expr [ASC | DESC] [NULLS FIRST | NULLS LAST]} ["," ...]
This exact syntax is supported by:
Other dialects have some variations:
DB2:
ORDER BY INPUT SEQUENCE
ORDER BY sort_specification [ {"," sort_specification}... ]
sort_specification:
    ORDER OF table_name
  | expr [ASC | DESC] [NULLS FIRST | NULLS LAST]
Hive provides ORDER BY, SORT BY, CLUSTER BY, DISTRIBUTE BY:
ORDER BY {column [ASC | DESC] [NULLS FIRST | NULLS LAST]} ["," ...]
SORT BY  {column [ASC | DESC] [NULLS FIRST | NULLS LAST]} ["," ...]
CLUSTER BY column [ {"," column}... ]
DISTRIBUTE BY column [ {"," column}... ]
ORDER BY {expr [ASC | DESC]} ["," ...]
ORDER BY {expr [ASC | DESC]} ["," ...] [WITH ROLLUP]
ORDER [SIBLINGS] BY {expr [ASC | DESC] [NULLS FIRST | NULLS LAST]} ["," ...]
ORDER BY {expr [ASC | DESC | USING operator] [NULLS FIRST | NULLS LAST]} ["," ...]
ORDER BY {expr [COLLATE collation] [ASC | DESC] [NULLS FIRST | NULLS LAST]} ["," ...]
ORDER BY {expr [COLLATE collation] [ASC | DESC]} ["," ...]
ORDER BY {expr [ASC | DESC] [NULLS FIRST | NULLS LAST]} ["," ...]