Database tips-select statement priority

Source: Internet
Author: User

Select statement execution sequence:
(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) with {cube | rollup}/Computing Using Aggregate functions
(7) having (8) Select
(9) distinct
(10) order by <order_by_list>
(11) <top_specification> <select_list>

Each step generates a virtual table, which is used as the input for the next step. Only the table generated in the last step is returned to the caller.
If no clause exists, skip the corresponding step.

1. From: Perform Cartesian product on the first two tables in the from clause to generate a virtual table vt1.

2. On: Apply the on filter to vt1. VT2 is inserted only when <join_condition> is true.

3. Outer (join): If outer join is specified, the row that does not match in the table is retained and added to VT2 as an external row to generate vt3.

If the from clause contains more than two tables, perform steps 1 to 3 on the result table generated by the previous join and the next table

Until all tables are processed.

4. Apply the where filter to vt3. Vt4 is inserted only for rows with <where_condition> true.

5. Group by: group the rows in vt4 by the column list in the group by clause to generate vt5.

6. cube | rollup: inserts the supergroup into vt5 to generate vt6.

7. Having: Apply the having filter to vt6. Vt7 is inserted only when

8. Select: process the select list and generate vt8.

9. distinct: Remove duplicate rows from vt8 to generate vt9.

10. Order by: sorts the rows in vt9 by the column list in the order by clause to generate a table (VC10 ).

11. Top: select a specified number or proportion of rows from the beginning of VC10, generate table vt11, and return it to the caller.

 

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.