1. Home
  2. Data Science
  3. SQL for Data Analysis
  4. What does WHERE EXISTS (SELECT 1 FROM orders o WHERE…

Added 30 Nov -0001

What does WHERE EXISTS (SELECT 1 FROM orders o WHERE o.cust_id = c.id) test?

  1. Whether the subquery returns exactly one row
  2. Whether the orders table contains a column literally named 1
  3. Whether every customer has the same order count
  4. Whether at least one matching order exists per customer Correct answer

Correct answer

D. Whether at least one matching order exists per customer

17 views

MCQSEXAM

Explanation

EXISTS returns true as soon as the correlated subquery produces any row, so it answers a yes-or-no question and stops scanning early. The selected literal 1 is a convention because the column list is irrelevant; SELECT * behaves identically. EXISTS also handles NULLs more predictably than IN, whose behaviour falls apart when the subquery returns NULL.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is D? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More SQL for Data Analysis MCQs

Practise all SQL for Data Analysis MCQs

Similar MCQs