CS FundamentalsHardGATE CS (PYQ pattern)

T(x) holds 1, 2, 3, 4, 5, 6, NULL and U(y) holds 2, 4, NULL. Let a, b, c be the row counts of (a) SELECT * FROM T WHERE x NOT IN (SELECT y FROM U) (b) SELECT * FROM T WHERE NOT EXISTS (SELECT 1 FROM U WHERE U.y = T.x) (c) SELECT * FROM T WHERE x NOT IN (SELECT y FROM U WHERE y IS NOT NULL) under standard SQL three-valued logic. What is (a, b, c)?

  1. A. (0, 5, 4)
  2. B. (4, 5, 4)
  3. C. (0, 4, 4)
  4. D. (4, 4, 5)

Correct answer: A. (0, 5, 4)

(a) U contains NULL, so x NOT IN (2, 4, NULL) is never TRUE: 0 rows. (b) NOT EXISTS only asks whether an equal row exists; 1, 3, 5, 6 and the NULL row (NULL = anything is not TRUE) all qualify: 5. (c) With NULL filtered out, 1, 3, 5, 6 qualify, but x = NULL gives NULL NOT IN (2, 4) = UNKNOWN: 4.

More DBMS and SQL questions

Exams that ask this topic