For AI agents: the complete documentation index is at llms.txt. Every page is also available as markdown by appending .md to its URL, or by sending an Accept: text/markdown request header.

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;