NOTE
SQL Execution Order
SQL's logical processing order begins with FROM, JOIN, and ON, followed by steps such as WHERE. These notes explain which fields are available at each stage.
This is a historical learning note and may contain outdated or incomplete understanding.
1. What It Is
1 FROM <left table>
2 ON <Join condition>
3 <join type> JOIN <right table>
4 Where <Where condition>
5 GROUP BY <group by list>
6 HAVING < having condition>
7 SELECT
8 DISTINCT <select list>
9 ORDER BY <order by condition>
10 LIMIT <limit number>
- Execute
FROM JOIN ONand create a temporary table. - Execute
WHEREand filter data. Aliases fromSELECTcannot be used here; only fields from theFROMandJOINtables can be used becauseSELECThas not executed yet. - Execute
GROUP BY. Values that are equal are grouped together, and aggregate functions can then be used afterSELECT. - Execute
HAVINGto filter values within each group after grouping. LikeWHERE, aliases fromSELECTcannot be used. - Execute
SELECTand choose the fields to display. - Execute
DISTINCTto remove duplicate rows. - Execute
ORDER BYto sort. Aliases fromSELECTcan be used here. - Execute
LIMITandOFFSETto limit the number of rows.
2. References
Drag to pan, scroll to zoom, and click a node to expand or collapse it. Large maps start with deeper levels collapsed; click nodes to expand them.
Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub