SORT BY Statement

SORT BY causes the result rows to be sorted according to the specified expressions.

By default, results are sorted in ascending order.

<sortByStatement> ::= "SORT BY" <expression> ( "," <expression> )* ;

A SORT BY expression can be the name of a column.

If two rows are equal according to the leftmost expression, they are compared according to the next expression and so on. If they are equal according to all specified expressions, they are returned in an implementation-dependent order.

Note: Sorting by an expression is not supported directly, but you can do it if you put the expression in the projection (COLUMNS statement) and assign it a column name with the AS statement

The following functions are supported:

  • ASC: Sort results in ascending order. This is the default order.
  • DESC: Sort results in descending order.

Examples

Sorting Expression Definition
sort by sys_eventTime ASC The result is sorted by time in ascending order.
sort by ll_sourceUser, sys_eventTime DESC The result is sorted by ll_sourceUser in ascending order (default), in case ll_sourceUser is the same, sort by sys_eventTime in descending order.