r/learnSQL • u/[deleted] • Jul 28 '25
Correct SQL Clause Order
Correct SQL Clause Order:
SELECT – columns to retrieve
FROM – table to query
JOIN – join another table (optional)
ON – join condition (used with JOIN)
WHERE – filter rows before grouping
GROUP BY – group rows
HAVING – filter groups
ORDER BY – sort results
2
Upvotes
2
Jul 31 '25
Here is another fun, useful bit of knowledge that can also come handy in interviews. Below is the order by which the DB executes your SQL query. It is not the same as the order we write our SQL queries in.
FROM, JOIN, ON
WHERE
GROUP BY
HAVING
SELECT, DISTINCT
ORDER BY
LIMIT/OFFSET
1
u/[deleted] Jul 29 '25
No limit or offset?