ORDER BY keyword

Sort the results of a query in ascending or descending order.

Syntax

SELECT ...
ORDER BY columnName [ASC | DESC] [, columnName [ASC | DESC] ...];

Default order is ASC. You can omit to order in ascending order.

Notes

Ordering data requires holding it in RAM. For large operations, we suggest you check you have sufficient memory to perform the operation.

Examples

Omitting ASC will default to ascending orderDemo this query
SELECT * FROM trades
WHERE timestamp IN '$now-1m..$now'
ORDER BY symbol;
Ordering in descending orderDemo this query
SELECT * FROM trades
WHERE timestamp IN '$now-1m..$now'
ORDER BY symbol DESC;
Multi-level orderingDemo this query
SELECT * FROM trades
WHERE timestamp IN '$now-1m..$now'
ORDER BY symbol, side DESC;