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
 which one is better in or exists

Author  Topic 

msrs

32 Posts

Posted - 2007-12-06 : 01:36:11
Dear all,
i am trying to improve the performance of stored procedures and functions in that in key word is there i have to replace with exists.which one will give better performance.


Thanks&Regards,

Msrs

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-12-06 : 03:24:45
Most often exists will perform better.



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

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2007-12-06 : 17:59:14
They behave differently around NULLs so it is not necessarily a search & replace operation. You should check each query. Consider:

select * from
(select '1' a union select '2' union select '3' union select null ) t1
where
exists
(select a from
(select '1' a union select '2' union select '3' union select null) t2 )
vs
select * from
(select '1' a union select '2' union select '3' union select null ) t1
where
a in
(select a from
(select '1' a union select '2' union select '3' union select null) t2 )
Go to Top of Page
   

- Advertisement -