Order of execution of sentence sentences in SQL language

Source: Internet
Author: User

Due to the non-computer trained, many computer-related knowledge is missing. A lot of things are working after the turn of the Niang after the mother to understand, especially the database this piece, has been a block of heart disease. Today I read the SQL from getting started to mastering, which is about the order of execution of the SQL clauses. I used to see it in the blog of a great God, and I told it in detail, but because I couldn't find the blog, I recorded it today. Understanding the order in which SQL clauses are executed is the basis for writing high-quality SQL code. The order of execution of each clause is as follows:

1) FROM clause.

2) WHERE clause.

3) GROUP by clause.

4) HAVING clause.

5) SELECT clause.

6) ORDER by clause.

The FROM clause in each clause of the SELECT statement is executed first, a virtual table is obtained from the FROM clause, and a new virtual table is generated from the virtual table that satisfies the criteria through the WHERE clause. After grouping the records in the new virtual table with the GROUP BY clause, the virtual table is updated, and the HAVING clause filters out records that satisfy the criteria in the most recent virtual table to form another virtual table. From the virtual table obtained from the previous step, the SELECT clause extracts the specified columns from select_list to form the updated virtual table, and the last order BY clause sorts them out for the final virtual table. Typically, people call the final virtual table a query result set.

Order of execution of sentence sentences in SQL language

Related Article

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.