SELECT * FROM FAMILY_DETAILS WHERE EXISTS(SELECT EMPLOYEE_ID FROM EMPLOYEE_MASTER WHERE EMPLOYEE_ID='EMP001')
SELECT * FROM FAMILY_DETAILS WHERE EMPLOYEE_ID IN(SELECT EMPLOYEE_ID FROM EMPLOYEE_MASTER WHERE EMPLOYEE_ID='EMP001')
I have these two queries in sql server 2008 R2. Both will give same results. Actually from these above queries output is only two rows, But in case if i have large number of records in that scenario Which one is better to use? and why?

Priyaranjan K SRank #45 · 32.5K reputationPosted Oct 29, 2015, 10:50 PM EDT
Hi ,
The guideline of the MS SQL query performance says that if we needs "IN" clause, instead of using "IN" clause we must use the "EXISTS" clause because "EXISTS" clause improve the performance of the query.
IN Clause
Returns true if a specified value matches any value in a sub query or a list.
EXISTS Clause
Returns true if a sub query contains any rows.
Ref:
http://sqlknowledgebank.blogspot.com/2012/11/in-exists-clause-and-their-performance.html
http://weblogs.sqlteam.com/mladenp/archive/2007/05/18/60210.aspx
Thanks,
If you found this useful Please Accept this as Answer.
Ravi PatelRank #439 · 5.7K reputationPosted Oct 29, 2015, 9:50 PM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Oct 29, 2015, 10:18 PM EDT