Aggregation & GROUP BY · SQL SQL
What will be the output of COUNT() versus COUNT(columnname) when the specified column contains several NULL values?
Practice question from Aggregation & GROUP BY (SQL SQL), with the correct answer and a step-by-step solution.
medium · MCQ · Q-5F1FE4
What will be the output of COUNT(*) versus COUNT(column_name) when the specified column contains several NULL values?
- A.COUNT(*) counts all rows in the group, whereas COUNT(column_name) excludes rows where column_name is NULL.Correct answer
- B.Both return the exact same count because SQL treats NULL as a value.
- C.COUNT(*) excludes rows with NULLs, whereas COUNT(column_name) includes them.
- D.Both return zero if any NULL values are present in the table.
Solution
COUNT(*) counts the total number of rows in a group regardless of contents or NULLs. COUNT(column_name) specifically counts only the non-null occurrences of that column.
More from Aggregation & GROUP BY
- What is the primary purpose of the SQL HAVING clause in an aggregation query?
- Consider a table named 'employees' with columns 'department' and 'salary'. Which of the following queries correctly returns the average sal…
- In standard SQL (ANSI SQL), if an aggregate function such as SUM() or COUNT() is used in a SELECT list, what rule applies to any other non-…
- How do standard SQL aggregate functions (such as COUNT, SUM, AVG) handle NULL values in their input columns?
Practise more SQL
Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.
Start practising freeFree to start · No credit card needed