Practice mode DBMS and SQL

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.