Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Inner joins vs Nested Queries ???

Author  Topic 

chamin.Lanerole
Starting Member

2 Posts

Posted - 2008-07-16 : 01:46:00
I want to know which performs better from a inner join and a nested query ? And please tell me what is the main difference between inner join and a nested query.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-16 : 03:17:26
i think inner join will perform much beeter when you have proper indexes on your joining columns.
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2008-07-16 : 12:17:25
Can you define what you mean by a "nested query?" are you talking about a sub-query/correlated sub-query or a derived table? If you are talking about a sub-query then that will almost always be slower. If you are talking about a derived table then there probably isn't any difference (depending on what sql decides to do with it). A sub-query is probably going to made a db call for each row in the result set so it is very inefficient.
Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2008-07-16 : 21:43:54
They can return completely different results so you should be careful interchanging them.
One returns a single column or null, the other returns one or more columns from zero or more rows, potentially removing or adding rows to your original query.

In the case where they are interchangable (as determined by joins to FK/PKs, unique constraints etc) I think the optimiser is capable of turning either into the same query.

You really should look to making sure you are returning the correct data before worrying about how fast it comes back.
Go to Top of Page
   

- Advertisement -