The clauses are logically processed in following order:1. FROM2. WHERE3. GROUP BY4. HAVING5. SELECT6. ORDER BY
From On Outer where group by rollup cube Having select Distinct order by top
In select Statement Order of Clauses is From Where Select
Here i am adding some more MS SQL Server objects logical execution order.1. FROM 2. ON 3. OUTER 4. WHERE 5. GROUP BY 6. CUBE | ROLLUP 7. HAVING 8. SELECT 9. DISTINCT 10 ORDER BY 11. TOPReference from blog.sqlauthority.com