Table T(dept) has rows ‘HR’, NULL, ‘IT’, NULL, ‘HR’. SELECT dept, COUNT(*) FROM T GROUP BY dept; How many rows does this query return?
Correct answer C. 3
Explanation
Although NULL = NULL is not true in a WHERE clause, GROUP BY treats all NULLs as one group. The result therefore has three groups: HR (2), IT (1) and NULL (2). The answer 4 assumes each NULL forms its own group, and 2 assumes NULLs are discarded. COUNT(*) counts the NULL group's two rows because it counts rows, not values.
Answer checked How we write and check questions
Discussion