Subqueries · SQL SQL

What is the primary operational difference between using the EXISTS operator with a correlated subquery versus using IN with a subquery?

Practice question from Subqueries (SQL SQL), with the correct answer and a step-by-step solution.

hard · MCQ · Q-4CFDFE

What is the primary operational difference between using the EXISTS operator with a correlated subquery versus using IN with a subquery?

  1. A.EXISTS returns true or false based on whether any rows are returned and typically short-circuits upon finding the first match, whereas IN evaluates the entire list of values.Correct answer
  2. B.IN allows multi-column comparisons whereas EXISTS only permits single-column comparisons.
  3. C.EXISTS requires an explicit JOIN clause inside the subquery, while IN does not.
  4. D.IN automatically removes duplicates, whereas EXISTS retains all duplicate rows from the underlying table.

Solution

EXISTS evaluates a boolean condition checking for row existence and can short-circuit (stop searching) as soon as the first matching row is found. IN evaluates the expression against a set of values, which conceptually involves materializing or checking the entire result set, though modern optimizers may rewrite them similarly.

More from Subqueries

All of Subqueries

Practise more SQL

Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.

Start practising free

Free to start · No credit card needed