Bird
0
0

You wrote this query: SELECT COUNT(column_name) FROM table_name; but it returns 0. The column has some NULL and some non-NULL values. What is the most likely problem?

medium📝 Debug Q14 of 15
SQL - Aggregate Functions
You wrote this query: SELECT COUNT(column_name) FROM table_name; but it returns 0. The column has some NULL and some non-NULL values. What is the most likely problem?
ACOUNT(column_name) counts NULL values, so it should not return 0.
BThe column_name is misspelled or does not exist in the table.
CCOUNT(*) should be used instead of COUNT(column_name) to count non-NULL values.
DThe table is empty, so COUNT(column_name) returns 0.
Step-by-Step Solution
Solution:
  1. Step 1: Check column existence

    If COUNT(column_name) returns 0 but column has non-NULL values, likely the column name is wrong or missing.
  2. Step 2: Understand COUNT behavior

    COUNT(column_name) counts non-NULL values; if column exists and has non-NULLs, result won't be zero.
  3. Final Answer:

    Column name is misspelled or does not exist. -> Option B
  4. Quick Check:

    Wrong column name causes zero count [OK]
Quick Trick: Check column spelling if COUNT(column) returns zero unexpectedly [OK]
Common Mistakes:
MISTAKES
  • Assuming COUNT(column) counts NULLs
  • Using COUNT(*) when column is misspelled
  • Ignoring empty table possibility without checking

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes