CS FundamentalsVery hardGATE CS (PYQ pattern)

IA(x): 1, 2, 3, NULL, 5 and IB(y): 2, 2, 5, 7. Let p = rows of IA satisfying x IN (SELECT y FROM IB), q = rows of IA satisfying x NOT IN (SELECT y FROM IB), and r = rows of IA JOIN IB ON IA.x = IB.y. What is (p, q, r)?

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

Correct answer: C. (2, 2, 3)

IN does not multiply rows: 2 and 5 qualify, p = 2. NOT IN: 1 and 3 qualify, NULL gives unknown, so q = 2. The join pairs row 2 with both 2s and 5 with one 5: r = 3.

More DBMS and SQL questions

Exams that ask this topic