ORDER BY keyword

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

Syntax

Flow chart showing the syntax of the ORDER BY keyword

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 order
ratings ORDER BY userId;
Ordering in descending order
ratings ORDER BY userId DESC;
Multi-level ordering
ratings ORDER BY userId, rating DESC;