- Some variants
This optional SQL feature covers the fundamental functionality of the order by clause in queries:
SELECT c
FROM (VALUES (1)
, (2)
) t(c)
ORDER BY cVariants
The order by clause allows the following keys types: ⓵ references to selected columns by name; ⓶ references to columns produced in the from clause if the query is simple0 and ⓷ expressions that contain at least one such column reference.1 Note that positional referencing by an unsigned integer value ⓸ is not standard SQL anymore.
- Expressions cannot contain select-names:
select c AS x FROM (VALUES (1), (2)) t(c) ORDER BY x * 2 - Also via bind parameter:
order by ?• Negative parameters (but not literals) reverse the direction - Also via bind parameter:
order by ?
Related
Articles
Order byHas Come a Long Way
Standard Features
Mandatory Features
Optional Features
Normative references
F850, “Top-level <order by clause>in <query expression>” is an optional feature in ISO/IEC 9075-2:2023. It first appeared in the 2008 edition.

