(5) SELECT
(5-2) DISTINCT
(5-3) TOP (<top_specification>)
(5-1) <select_list>
(1) FROM
(1-J) <left_table> <join_type> JOIN <right_table> ON <on_predicate>
|
(1-A) <left_table> <apply_type> APPLY <right_table_expression> AS <alias>
|
(1-P) <left_table> <left_table> PIVOT(<pivot_specification>) AS <alias>
|
(1-U) <left_table> UNPIVOT(<unpivot_specification>) AS <alias>
(2) WHERE <where_predicate>
(3) GROUP BY <group_by_specification>
(4) HAVING <having_predicate>
(6) ORDER BY <order_by_list>
SQL与其他编程语言最明显的不通是代码的处理顺序,在其他编程语言中,代码是按照编写的顺序来执行的,但在SQL中,第一个要处理的子句是FROM子句,尽管SELECT语句第一个出现,但总是放在最后处理。