Difficulty: Easy
Correct Answer: Applies — COUNT() counts all rows regardless of NULLs
Explanation:
Introduction / Context:
SQL provides aggregate functions for summarization. COUNT() is widely used, yet developers sometimes confuse it with COUNT(column). This question distinguishes these two behaviors.
Given Data / Assumptions:
Concept / Approach:
COUNT() is defined to include every row that survives WHERE and JOIN conditions, independent of NULLs. It is the correct choice when you need the cardinality of the result set. Use COUNT(column) when you specifically want to ignore NULLs in that column.
Step-by-Step Solution:
Write the query with necessary joins and WHERE predicates.Use COUNT() to count the resulting rows.If you need to exclude rows where a column is NULL, use COUNT(column).Combine with GROUP BY for per-group counts.Verify by testing with rows that contain NULLs.
Verification / Alternative check:
Create a table with NULLs in several columns; COUNT() equals total rows, while COUNT(col) is lower when NULLs exist.
Why Other Options Are Wrong:
COUNT() never ignores rows due to NULLs. Primary keys or the presence of WHERE do not alter the definition.
Common Pitfalls:
Accidentally using COUNT(col) and misreporting totals; forgetting that joins can duplicate rows before counting.
Final Answer:
Applies — COUNT(*) counts all rows regardless of NULLs
Discussion & Comments