SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 difference between "join" and "exists"
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

slimt_slimt
Aged Yak Warrior

Switzerland
746 Posts

Posted - 07/30/2007 :  12:28:29  Show Profile  Reply with Quote
hi,

what is the main difference of using join or using exists.

e.g.1.
select t1.id, t1.name from table1 t1
join table2 t2
t2.id = t1.id

join table3 t3
t2.id = t3.id

where
t1.name like '%something'

e.g.2.

select t1.id, t1.name from table t1

where t1.name like '%something'
and (select t2.id from table2 t2
join table3 t3
t2.id = t3.id)

what is the main difference and how does this impact on the output?

thanx

SwePeso
Patron Saint of Lost Yaks

Sweden
30265 Posts

Posted - 07/30/2007 :  12:48:21  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Any join can produce unwanted result by duplicating a record.
An exists check works much like IN but more efficient.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

spirit1
Cybernetic Yak Master

Slovenia
11751 Posts

Posted - 07/30/2007 :  13:08:26  Show Profile  Visit spirit1's Homepage  Reply with Quote
all you need to know
http://weblogs.sqlteam.com/mladenp/archive/2007/05/18/60210.aspx

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000