Click here to Skip to main content
15,901,666 members
Please Sign up or sign in to vote.
1.80/5 (3 votes)
See more:
Which one is faster? Join or Subquery?
Posted

It depends on many factors. Please, see past answers and CP Knowledge Base articles[^].
 
Share this answer
 
There is no clear cut answer. Typically in SQL Server you would you JOINs, but in Oracle you'd use Subqueries. The each DBMS is designed to optimize that way, but it isn't always true. Here are a couple of nice examples on how to use the SQL Server Execution Plan to test performance of JOINs and Subqueries; if you've never used that.

http://blog.sqlauthority.com/2010/06/06/sql-server-subquery-or-join-various-options-sql-server-engine-knows-the-best/[^]

http://sqlstudies.com/2013/05/02/comparing-an-inner-join-vs-a-subquery/[^]
 
Share this answer
 
Hi,

Check this...

Joins Vs Subqueries[^]

Hope this will help you.

Cheers
 
Share this answer
 
Joins and subqueries are semantically different and may give different results.
For those cases when they are equivalent the optimizer on all modern RDBs will know that and convert subqueries to joins where it gives a better result.

So the answer is, use the query that gives the right result.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900