SORT
Order rows by one or more expressions with optional direction specifiers.
Syntax
SORT sortExpression (, sortExpression)* [,]?
Parameters
- sortExpression - Field or expression to sort by, with optional
ASCorDESCdirection (default is ascending)
Description
The SORT command orders rows in the dataset according to the specified sort expressions. Multiple sort expressions can be provided, with later expressions acting as tiebreakers when earlier expressions have equal values.
Each sort expression can optionally specify a direction using ASC (ascending) or DESC (descending). When no direction is specified, ascending order is used by default.
Sort expressions can reference any field available in the current dataset context, including calculated fields from previous SET commands and fields from joined datasets. Expressions can also include function calls and calculations.
Related Commands
- LIMIT - Restrict the number of rows returned (commonly used with SORT)