SQL & Relational Databases (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)
What is the difference between `EXISTS` and `IN`?
senior LevelSystem Design
In Simple Words:
IN: Evaluates all subquery results, builds a candidate set, and checks if the outer value exists in that set. Fails or produces unexpected results if subquery returnsNULLwithNOT IN.EXISTS: Returns a booleantrueas soon as the first matching row is found (short-circuits immediately). Much faster when the subquery touches a large table with an index.