CS FundamentalsVery hardGATE CS (PYQ pattern)

Table DU(a, b): (1,NULL), (1,NULL), (2,3), (2,3), (NULL,5), (NULL,5), (1,2). Let x = rows returned by SELECT DISTINCT a, b FROM DU, y = COUNT(DISTINCT a), and z = rows returned by SELECT a FROM DU GROUP BY a. What is the triple (x, y, z)?

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

Correct answer: B. (4, 2, 3)

DISTINCT and GROUP BY treat NULLs as equal, so x = 4 distinct pairs ((1,NULL), (2,3), (NULL,5), (1,2)) and z = 3 groups (1, 2, NULL); COUNT(DISTINCT a) ignores NULL, so y = 2.

More DBMS and SQL questions

Exams that ask this topic