SQL Cheat Sheet/Sort rows

Order query results ascending or descending.

Section: Sorting and Limiting

Sort rows

sql
sql
SELECT id, created_at
FROM orders
ORDER BY created_at DESC, id ASC;
Explanation

ORDER BY is applied after filtering and grouping.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Sorting and Limiting
Limit returned rows
Return only the first N rows.
OpenIn sheetsqlsame section
Paginate with LIMIT and OFFSET
Skip rows and return a page-sized result set.
OpenIn sheetsqlsame section
Fetch first rows
Use standard SQL row limiting syntax.
OpenIn sheetsqlsame section
Select all columns
Return all columns from a table.
Filter with equality
Return rows matching an exact value.
Inner join two tables
Return rows with matches in both tables.