Bird
0
0

What is the main difference between COUNT(*) and COUNT(column_name) in SQL?

easy📝 Conceptual Q11 of 15
SQL - Aggregate Functions
What is the main difference between COUNT(*) and COUNT(column_name) in SQL?
A<code>COUNT(*)</code> counts only rows where all columns are NOT NULL, <code>COUNT(column_name)</code> counts all rows.
B<code>COUNT(*)</code> and <code>COUNT(column_name)</code> always return the same result.
C<code>COUNT(*)</code> counts only NULL values, <code>COUNT(column_name)</code> counts non-NULL values.
D<code>COUNT(*)</code> counts all rows, while <code>COUNT(column_name)</code> counts only rows where the column is NOT NULL.
Step-by-Step Solution
Solution:
  1. Step 1: Understand COUNT(*)

    COUNT(*) counts every row in the table, including those with NULL values in any column.
  2. Step 2: Understand COUNT(column_name)

    COUNT(column_name) counts only rows where the specified column is NOT NULL, ignoring rows where that column is NULL.
  3. Final Answer:

    COUNT(*) counts all rows; COUNT(column_name) counts only non-NULL values in that column. -> Option D
  4. Quick Check:

    COUNT(*) counts all rows, COUNT(column) skips NULLs [OK]
Quick Trick: Remember: * counts all rows, column counts non-NULL only [OK]
Common Mistakes:
MISTAKES
  • Thinking COUNT(column) counts NULL values
  • Assuming COUNT(*) ignores NULLs
  • Believing both always return same count

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes