The short answer
A simplified logical order is:
FROM / JOIN
WHERE
GROUP BY
HAVING
SELECT
DISTINCT
ORDER BY
LIMITSo although we write:
SELECT ...
FROM ...
WHERE ...
GROUP BY ...
HAVING ...
ORDER BY ...SQL logically processes FROM first.
Interview gotcha: the order you write clauses is not the order SQL runs them.