Geeks With Blogs

DevJef's Mumbo-Jumbo «There's a bit of SQL in all of us»

If you write a SQL query, it’s important to know when certain pieces of you query are executed. For example, it’s possible that some statement in your query interferes with another part of your query, because of the execution time of a specific piece.


The order of execution is:


1. FROM Clause


3. WHERE Clause

4. GROUP BY Clause

5. CUBE / ROLLUP Clause

6. HAVING Clause

5. SELECT Clause

6. DISTINCT Clause

7. TOP Clause

8. ORDER BY Clause


So in many cases this won’t be a problem. But in some cases this can pose as a problem. In those cases it’s important to know the order of execution if you want to debug your query.


Sources: Logical Query Processing

Posted on Saturday, October 15, 2011 9:36 PM SQL Scripts , SQL Server | Back to top

Comments on this post: Query order of execution

# re: Query order of execution
Requesting Gravatar...
Dit lijkt wel heel veel op de volgorde van de Linq syntax!
Left by Dries Marckmann on Oct 22, 2011 8:48 AM

Your comment:
 (will show your gravatar)

Copyright © DevJef | Powered by: