Execution sequence of SQL statements with Left Join, joinsql

Source: Internet
Author: User

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!

 

 

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.