Practice mode DBMS and SQL

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.

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.