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
 difference between "join" and "exists"

Author  Topic 

slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2007-07-30 : 12:28:29
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

30421 Posts

Posted - 2007-07-30 : 12:48:21
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

11752 Posts

Posted - 2007-07-30 : 13:08:26
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
   

- Advertisement -