Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EXISTS vs.IN

Status
Not open for further replies.

cricketer1

Technical User
Mar 15, 2001
76
US
What is the difference between using IN and EXISTS in subqueries and which is preferred.

Thanks
 
in is used in simple subqueries (can be run stand alone)
exists is used in correlated subqueries (dependant upon parent). Existance of rows meeting a particular query
 
thanks, any idea which one is preferred...IN is faster or EXISTS?
 
I looked at the execution plan of two queries that were written with in and exists and the execution plan was exactly the same.

Personally, I avoid using subqueries, you generally get better performance out of doing a join instead. This is not always true, so you should probably test both the subquery and the join.

Questions about posting. See faq183-874
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top