Bird
0
0

Identify the error in this query that tries to count all rows including NULLs in score column:

medium📝 Debug Q14 of 15
SQL - Aggregate Functions
Identify the error in this query that tries to count all rows including NULLs in score column:
SELECT COUNT(score) + COUNT(NULL) FROM results;
AThe query sums counts correctly
BCOUNT(score) counts all rows including NULLs
CCOUNT(NULL) counts NULLs as 1
DCOUNT(NULL) returns 0
Step-by-Step Solution
Solution:
  1. Step 1: Understand COUNT(NULL) behavior

    COUNT(NULL) always returns 0 because the NULL expression is always NULL and thus never counted.
  2. Step 2: Analyze COUNT(score)

    COUNT(score) counts only non-NULL values in score column, not all rows.
  3. Final Answer:

    COUNT(NULL) returns 0 -> Option D
  4. Quick Check:

    COUNT(NULL) always returns 0 [OK]
Quick Trick: COUNT(NULL) always returns zero, use COUNT(*) for all rows [OK]
Common Mistakes:
MISTAKES
  • Thinking COUNT(NULL) counts NULLs
  • Assuming COUNT(column) counts NULLs
  • Adding COUNT(NULL) to count rows

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes