Query order of execution

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
7. SELECT Clause
8. DISTINCT Clause
9. TOP Clause
10. 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
Also check out this video if you want to learn more about this subject.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: