A table has 10 rows and the column col is NULL in 3 of them. What do COUNT(*) and COUNT(col) return?
Correct answer
A. 10 and 7
19 views
A. 10 and 7
19 views
COUNT semantics: COUNT(*) counts rows, while COUNT(col) counts only non-NULL values of that column, so three NULLs reduce the second result to 7. The same NULL elimination affects AVG and SUM, where NULLs are skipped rather than treated as zero. COUNT(DISTINCT col) goes further and also removes duplicates among the non-NULL values.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is A? Ask here and get an explanation.