Not necessarily, I have never studied SQL query in depth before, recently bought a T-SQL query book, the previously ignored problems are recorded
In the past, I used SQL server as a relational database, which is used to manage data in relational words in the form of tables. Later, some SQL statements look strange and I have no idea how to manage it.
Actually
"Writing SQL statements requires a method of thinking oriented to declarations and sets, rather than process-oriented (set is the focus)." (PS: tables in the database are a set, the set is unordered !)
I have never paid too much attention to the logic sequence of SQL statement execution before. During the research on linq, linq emphasizes the execution sequence of SQL statements. I also paid attention to it when reading books.
(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> partition (<shortt_specification>) as <alias>
| (1-u) <left_table> unpartitioned (<uneffect_specification>) as <alias>
(2) where <where_predicate>
(3) group by <group_by_specification>
(4) having (6) order by <order_by_list>
We can see that
The first phase is from: identifies the query source and processes the table (SET) operator.
In the second stage, where is selected based on the predicate (query condition ).
The third stage is gruop by grouping based on the specified list name.
The fourth stage is having's selection based on the predicates in having.
The fifth stage is select.
The sixth phase is to sort order by specified columns.