CS FundamentalsModerateGATE CS (PYQ pattern)

DP(d): 1, 2, 3. EP(e, d): (1,1), (2,1), (3,1), (4,3). For SELECT DP.d, COUNT(*) AS a, COUNT(EP.e) AS b FROM DP LEFT JOIN EP ON DP.d = EP.d GROUP BY DP.d, what is the sum over all groups of (a - b)?

  1. A. 0
  2. B. 1
  3. C. 2
  4. D. 3

Correct answer: B. 1

Department 2 has no employee: the left join keeps it as one row of NULLs, so COUNT(*) = 1 but COUNT(EP.e) = 0 (NULL skipped); other groups agree (3 and 3, 1 and 1). The sum of (a - b) is 1.

More DBMS and SQL questions

Exams that ask this topic