MySQL SQL statement Execution order

Source: Internet
Author: User

SQL statement SELECT statement Query order

  1. (7) SELECT
  2. (8) DISTINCT <select_list>
  3. (1) from <left_table>
  4. (3) <join_type> join <right_table>
  5. (2) on <join_condition>
  6. (4) WHERE <where_condition>
  7. (5) GROUP by <group_by_list>
  8. (6) having
  9. (9) ORDER by <order_by_condition>
  10. (Ten) LIMIT <limit_number>


One, executes the FROM statement, the MySQL is executes from left to right, Oracle is executes from right to left, the SQL statement executes the procedure, will produce a virtual table, is used to save the SQL statement execution result (this is the key), Executing the FROM statement results in a virtual table called VT1 (vitual table 1), VT1 is generated from the Cartesian product

Second, the execution on to filter

Filter out non-conforming data according to the conditions on the back, parameter VT2

Iii. Types of execution links

Inner JOIN, left JOIN, right link, outer join outer link, full outer join connection

VT3 after execution

Iv. executing the conditions behind where

When using the Where condition, be aware that the group function cannot be used, and the alias of the field cannot be used in the condition

For example select City as C from T WHERE c= ' Shanghai '

V. Implementing GROUP BY

Vi. implementation of having a filter

HAVINGClauses are GROUP BY used in conjunction with clauses, which can be followed by the condition of the group function

VII. implementation of SELECT

Viii. execute DISTINCT, remove duplicate data

Ix. ORDER BY Statement execution

X. Executing paging statements

Transferred from: http://blog.csdn.net/u010833154/article/details/50696583

MySQL SQL statement Execution order

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.