CS FundamentalsHardGATE CS · Product-company placement

Table T(x) has rows (1), (2), (3) and table U(y) has rows (2), (NULL). What do these two queries return? Q1: SELECT COUNT(*) FROM T WHERE x NOT IN (SELECT y FROM U); Q2: SELECT COUNT(*) FROM T WHERE NOT EXISTS (SELECT 1 FROM U WHERE U.y = T.x);

  1. A. Q1 = 2, Q2 = 2
  2. B. Q1 = 0, Q2 = 2
  3. C. Q1 = 0, Q2 = 0
  4. D. Q1 = 2, Q2 = 0

Correct answer: B. Q1 = 0, Q2 = 2

x NOT IN (2, NULL) means x <> 2 AND x <> NULL; the second part is UNKNOWN, so no row qualifies and Q1 = 0. NOT EXISTS only asks whether a matching row exists, so 1 and 3 qualify and Q2 = 2.

More DBMS and SQL questions

Exams that ask this topic