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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

T-SQL Efficiency with multiple tables. joins vs just listing tables

Status
Not open for further replies.

JScannell

Programmer
Jan 9, 2001
306
0
0
US
This is probably an age-old question, but I need to know the answer for something I am working on. The performance of a very large stored procedure has come into question and I am analyzing everything.
(Ordinarilly I could run the two queries myself but the real ones are embedded in the stored procedure and are based on temp tables)

Which of the following would be more efficient.

This way:

select [a.columns], [b.columns], [c.columns]
from customers a,
orders b,
payments c
where b.customer_id = a.customer_id
and c.order_id = b.order_id
order by a.customer_id, b.order_id, c.payment_date

or this:

select [a.columns], [b.columns], [c.columns]
from customers a
inner join orders b on b.customer_id = a.customer_id
inner join payments c on c.order_id = b.order_id
order by a.customer_id, b.order_id, c.payment_date

Thanks in advance,

Jerry Scannell
 
They are the same.

When you run a SQL query, SQL Server must first parse the query to decide how to go about executing it. The results of this part of the process is the execution plan. Both of your queries will generate the same execution plan so there is no difference in performance.

To see this for yourself, load both queries in to a query window. Press CTRL-M. You won't "see anything happen". Then run the query by pressing F5. After the query is done, you should see an "Execution plan" tab within SQL Server Management Studio. Comparing the execution plan should reveal that they are the same.



-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
To add to George's comment...while they both perform the same, the version with the ON statements is easier to read and troubleshoot as the columns being joined on are grouped with the tables they refer to.

-SQLBill

The following is part of my signature block and is only intended to be informational.
Posting advice: FAQ481-4875
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top