Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select statement processing order

Status
Not open for further replies.

Joiner

MIS
Jun 20, 2001
22
US
Hi there.
I'm trying to learn more about the basic implementation of SELECT statements in MSSQL. My understanding is that SQL will first evaluate the WHERE clause, followed by the ORDER BY and GROUP BY clauses (if any), then the HAVING clause (if any), and finally evaluate any aggregate or computed columns in the SELECT clause. I have noticed, however, that under certain circumstances the HAVING clause will be processed immediately after the WHERE clause and before the ORDER BY. Does anyone know where I can find more information on this? BOL and my current literature isn't quite detailed enough.
Many thanks.
 
Joiner,
SQL process the SELECT statement in following order, and it maintain intermediate result sets to accomplish this.

1. WHERE
2. GROUP BY
3. HAVING
4. ORDER BY

You can see this by using Execution Plan.

If someone had noticed different processing order, please intimate in the forum.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top