Execution sequence of SQL statements with Left Join, joinsql
Basic SQL Execution Sequence
SQL statements are executed in a certain order. Understanding this sequence is of great help for SQL usage and learning.
1. from
Select a table or source to form a result set.
2. where
Then, use where to filter the result set. Filter the required information to form a new result set.
3. group
Group new result sets.
4. having
Filter out the desired group.
5. select
Select columns.
6. order
When all the conditions are completed. Last sorting.
Execution sequence of SQL statements with connections (in the Left Join column)
In my understanding, whether or not other tables are connected in SQL statements. In any case, a result set must be formed first. The subsequent order remains unchanged!
However, when using a connection, the method for forming a result set is slightly different. This is related to the implementation principle of Left Join.
Select a. name, B. name
From T_left a // 1
Left Join T_Right B // 3
ON a. id = B. id // 2
The result set is formed using Left Join.
1.First, perform the Cartesian Product Operation on the first two tables in the From clause. Computation results form a set of results.
2.ON filters the above result set based ON conditions to form a new result set.
3.Take the left join as an example. If no matching row exists in T_left. Add the rows other than the rows in T_left to the result set above to form a new result set.
4.If multiple tables exist, repeat 1 ~ 3 process!