Recall & Review
beginner
What does the COUNT function do in SQL?
The COUNT function counts the number of rows that match a specified condition or all rows if no condition is given.
Click to reveal answer
beginner
How do you count all rows in a table named 'employees'?
Use:
SELECT COUNT(*) FROM employees; This counts every row in the 'employees' table.Click to reveal answer
intermediate
What is the difference between
COUNT(*) and COUNT(column_name)?COUNT(*) counts all rows including those with NULLs. COUNT(column_name) counts only rows where the column is NOT NULL.Click to reveal answer
beginner
Can COUNT be used with a WHERE clause? Give an example.
Yes. Example:
SELECT COUNT(*) FROM employees WHERE department = 'Sales'; counts only employees in Sales.Click to reveal answer
intermediate
What will
SELECT COUNT(DISTINCT department) FROM employees; return?It returns the number of unique departments in the employees table, ignoring duplicates.
Click to reveal answer
What does
COUNT(*) count in a table?✗ Incorrect
COUNT(*) counts every row regardless of NULL values.Which query counts only rows where the 'age' column is NOT NULL?
✗ Incorrect
COUNT(age) counts rows where 'age' is not NULL.How to count unique values in a column 'city'?
✗ Incorrect
COUNT(DISTINCT city) counts unique city values.What does this query do?
SELECT COUNT(*) FROM employees WHERE salary > 50000;✗ Incorrect
The WHERE clause filters employees with salary > 50000 before counting.
If a column has NULL values, which COUNT counts them?
✗ Incorrect
COUNT(*) counts all rows including those with NULLs.Explain how the COUNT function works and how it handles NULL values.
Think about counting all rows versus counting only non-NULL values in a column.
You got /4 concepts.
Describe how to count unique values in a column using COUNT.
Use DISTINCT keyword inside COUNT.
You got /3 concepts.