Execution order of SQL statements with left JOIN

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.