Recall & Review
beginner
What does the SQL COUNT(*) function do?
COUNT(*) counts all rows in a table, including rows with NULL values in any column.
Click to reveal answer
beginner
How does COUNT(column_name) differ from COUNT(*)?
COUNT(column_name) counts only rows where the specified column is NOT NULL, ignoring rows with NULL in that column.
Click to reveal answer
intermediate
What will COUNT(1) count in a SQL query?
COUNT(1) counts all rows just like COUNT(*), because 1 is a constant and not NULL, so it counts every row.
Click to reveal answer
beginner
If a column has NULL values, will COUNT(column) include those rows?
No, COUNT(column) excludes rows where the column value is NULL. Only non-NULL values are counted.
Click to reveal answer
intermediate
Can COUNT be used to count distinct values? How?
Yes, use COUNT(DISTINCT column_name) to count unique non-NULL values in that column.
Click to reveal answer
What does COUNT(*) return in a SQL query?
✗ Incorrect
COUNT(*) counts every row in the table, regardless of NULL values.
Which COUNT function counts only non-NULL values in a column?
✗ Incorrect
COUNT(column_name) counts only rows where the column is NOT NULL.
What will COUNT(1) return compared to COUNT(*)?
✗ Incorrect
COUNT(1) counts all rows because 1 is a constant and never NULL.
How to count unique non-NULL values in a column?
✗ Incorrect
COUNT(DISTINCT column_name) counts unique non-NULL values.
If a column has NULL values, what does COUNT(column) do with those rows?
✗ Incorrect
COUNT(column) ignores rows where the column value is NULL.
Explain how COUNT(*) and COUNT(column_name) behave differently when counting rows.
Think about whether NULL values are included or excluded.
You got /3 concepts.
Describe how to count unique values in a column using COUNT.
Focus on the DISTINCT keyword.
You got /3 concepts.