2012-02-07 19:39 First where Condition 1, then group by condition 2 again order by condition 3
If a GROUP BY clause is declared, the output is divided into different groups that match one or more values. If there is a HAVING clause, it eliminates those groups that do not meet the given criteria.
If the ORDER BY clause is declared, the returned rows are sorted in the order specified. If an ORDER by is not given, the data rows are given in the way that the system considers the fastest generation possible.
Although the complete syntax of the SELECT statement is more complex, its main clauses can be summarized as follows:
SELECT select_list
[Into new_table]
From Table_source
[WHERE search_condition]
[GROUP by Group_by_expression]
[Having search_condition]
[ORDER by order_expression [ASC | DESC]]
You can use the UNION operator between queries to combine the results of a query into a single result set.
In other words, order by is placed on the last side.
SQL Server where, group by, order by execution sequence