Bird
0
0

Why does the aggregate function COUNT(column_name) exclude NULL values, but COUNT(*) includes them?

hard📝 Conceptual Q10 of 15
SQL - Aggregate Functions
Why does the aggregate function COUNT(column_name) exclude NULL values, but COUNT(*) includes them?
ACOUNT(column_name) counts only non-NULL values; COUNT(*) counts all rows regardless of NULLs
BCOUNT(column_name) counts all rows; COUNT(*) counts only non-NULL values
CBoth COUNT(column_name) and COUNT(*) exclude NULLs
DCOUNT(column_name) returns NULL if any NULL exists; COUNT(*) returns zero
Step-by-Step Solution
Solution:
  1. Step 1: Understand COUNT(column_name) behavior

    It counts only rows where the column value is NOT NULL.
  2. Step 2: Understand COUNT(*) behavior

    It counts all rows regardless of any NULL values in columns.
  3. Final Answer:

    COUNT(column_name) counts only non-NULL values; COUNT(*) counts all rows regardless of NULLs -> Option A
  4. Quick Check:

    COUNT(column) excludes NULLs; COUNT(*) counts all rows = B [OK]
Quick Trick: COUNT(column) excludes NULLs; COUNT(*) counts all rows [OK]
Common Mistakes:
MISTAKES
  • Confusing COUNT(column) and COUNT(*) behavior
  • Assuming COUNT(column) counts NULLs
  • Thinking COUNT(*) excludes NULL rows

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes