Bird
0
0

Consider the query: SELECT COUNT(employee_id) FROM staff; but it returns 0 even though the table has rows. What is the most likely reason?

medium📝 Debug Q14 of 15
SQL - Aggregate Functions
Consider the query: SELECT COUNT(employee_id) FROM staff; but it returns 0 even though the table has rows. What is the most likely reason?
AThe column <code>employee_id</code> contains only NULL values
BThe table <code>staff</code> is empty
CCOUNT(employee_id) counts all rows including NULLs
DSyntax error in the query
Step-by-Step Solution
Solution:
  1. Step 1: Understand COUNT(column) behavior

    COUNT(column) counts only non-NULL values in that column.
  2. Step 2: Analyze why count is zero

    If all employee_id values are NULL, COUNT returns 0 even if rows exist.
  3. Final Answer:

    The column employee_id contains only NULL values -> Option A
  4. Quick Check:

    COUNT(column) excludes NULLs [OK]
Quick Trick: COUNT(column) returns 0 if all values are NULL [OK]
Common Mistakes:
MISTAKES
  • Assuming COUNT(column) counts all rows
  • Thinking table is empty without checking data
  • Assuming syntax error without checking query

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes