During one of my interviews, I faced this question “what is the difference Between IN and EXISTS? Answer: Consider this example I have two tables TableA and TableB, where TableA contains Name of an Employees and TableB Contains the address code of the Employees,both can be joined by ID and ID2.
- Returns true if specified value matches any value in the sub query or a list.
- The sub query will run first and then only outer query.
WHERE id IN (SELECT id
- Return true if sub query contain any rows.
- The Outer query will ran first and then only sub query.
FROM dbo.tablea AS a
WHERE EXISTS (SELECT id2
WHERE id2 = a.id)
Hope everyone like this this article.Please give views and suggestions