CS FundamentalsHardGATE CS (PYQ pattern)

DD(id, k, v): (1,1,a), (2,1,b), (3,2,c), (4,2,d), (5,2,e), (6,3,f), (7,NULL,g), (8,NULL,h). A cleanup runs DELETE FROM DD WHERE id NOT IN (SELECT MIN(id) FROM DD GROUP BY k); How many rows remain?

  1. A. 5
  2. B. 3
  3. C. 6
  4. D. 4

Correct answer: D. 4

GROUP BY puts both NULL keys in one group, so the subquery returns ids 1, 3, 6, 7 (the minimum of each of k = 1, 2, 3, NULL). Rows with other ids are deleted, leaving 4 rows. A join-based cleanup using k = k would keep both NULL rows (5 rows).

More DBMS and SQL questions

Exams that ask this topic