Table Emp(id, dept, salary) has rows (1,’HR’,3000), (2,’IT’,5000), (3,’IT’,4000), (4,’HR’,NULL), (5,’Ops’,2000). SELECT COUNT(*), COUNT(salary) FROM Emp; What does this query return?
Correct answer A. 5, 4
Explanation
COUNT(*) counts rows regardless of their contents, so all 5 rows are counted. COUNT(salary) counts only rows where salary is not NULL, so the row for id 4 is skipped and the result is 4. Expecting 5, 5 is the common slip: every aggregate applied to a column ignores NULLs, and COUNT(*) is the one form that does not look at any column.
Answer checked How we write and check questions
Discussion