the underlying SQL execution order
SQL statements are executed in a certain order. Understanding this order is a great help in using and learning SQL.
1.from
First select a table, or source, to form a result set.
2.where
Then use where to filter the result set. Filter out the information needed to form a new result set.
3.group by
Group the new result set.
4.having
Filter out the groups you want.
5.select
Select the column.
6.order by
When all the conditions are done. The last sort.
SQL statement Execution order with connection (with left join as column)
My understanding is that the SQL statement is no matter whether the other tables are connected or not. In any case, a result set must be formed first. The subsequent order is the same!
Only when you use joins, the result set is formed slightly differently. This is related to the implementation principle of the left join.
Select A.name,b.name
From T_left a//1
Left Join T_right b//3
On a.id = b.ID//2
This is how you use a left Join to form a result set.
1. The Cartesian product operation is performed first on the first two tables in the FROM clause. The results of the operation form a result set.
2. on conditionally, the upper result set is filtered to form a new result set.
3. take left join as an example, if there is an unmatched line in the T_left. The new result set is formed by adding these lines in the t_left to the result set above in the form of an outer row.
4. If there are more than one table, repeat the process!
Execution order of SQL statements with left JOIN