the full execution order of the SQL SELECT statement:1, the FROM clause assembles data from different data sources;2, where clause filters the record rows based on the specified criteria;3, the GROUP BY clause divides the data into multiple groupings;4, using aggregation function to calculate;5, using the HAVING clause to filter the grouping;6and calculates all the expressions;7、SelectThe field;
8, use order by to sort the result set. The most obvious feature of the SQL language differs from other programming languages is the order in which the code is processed. In most database languages, code is processed in encoded order. In the SQL statement, however, the first child sentence to be processed from, rather than the first occurrence of a select.
Steps for SQL query processing sequence number: (1) from <left_table> (3) <join_type> Join <right_table> (2) on <join_condition> (4) WHERE <where_condition> (5) GROUP by <group_by_list> (6) with {CUBE |ROLLUP} (7) Having (8) SELECT (9) DISTINCT (9) ORDER by <order_by_list> (Ten) <TOP_specification> <select_list>each of these steps produces a virtual table that is used as input to the next step. These virtual tables are not available to callers (client applications or external queries). Only the table generated in the last step will be given to the caller. If you do not specify a clause in the query, the corresponding step is skipped. Introduction to the Logical query processing phase:1, from: Performs a Cartesian product (cross join) on the first two tables in the FROM clause, generating the virtual table VT1. 2, on: Apply an on filter to VT1, only those that are true are inserted into the TV2. 3, OUTER (join): If a OUTER join (relative to a cross join or inner join) is specified, a matching row in the reserved table is added to VT2 as an outer row, generating TV3. If the FROM clause contains more than two tables, repeat steps 1 through 3 for the result table and the next table generated by the previous join until you have finished processing all the table locations. 4, where: Apply the WHERE filter to TV3, only the rows that are true are inserted into the TV4. 5, GROUP by: The rows in the TV4 are grouped by the list of columns in the GROUP BY clause, and the TV5 is generated. 6, cute|ROLLUP: Inserts a super-group into the VT5 to generate VT6. 7, having: Apply the having filter to VT6, only the group that is true is inserted into the VT7. 8, select: Processes the select list, producing VT8. 9, DISTINCT: Remove duplicate rows from VT8, product VT9. Ten, ORDER BY: Generates a cursor (VC10) in the order of the columns in the VT9 by the column list in the ORDER BY clause. One, TOP: Selects the specified number or scale of rows from the beginning of the VC10, generates the table TV11, and returns it to the caller.
Full execution order of SQL SELECT statements