0
0
SQLquery~10 mins

COUNT(*) vs COUNT(column) difference in SQL - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to count all rows in the table.

SQL
SELECT [1] FROM employees;
Drag options to blanks, or click blank then click option'
ACOUNT(1)
BCOUNT(employee_id)
CCOUNT(*)
DCOUNT(DISTINCT employee_id)
Attempts:
3 left
💡 Hint
Common Mistakes
Using COUNT(column) when you want to count all rows including NULLs.
Confusing COUNT(*) with COUNT(DISTINCT column).
2fill in blank
medium

Complete the code to count only non-NULL values in the salary column.

SQL
SELECT [1] FROM employees;
Drag options to blanks, or click blank then click option'
ACOUNT(*)
BCOUNT(salary)
CCOUNT(1)
DCOUNT(DISTINCT salary)
Attempts:
3 left
💡 Hint
Common Mistakes
Using COUNT(*) which counts all rows including NULLs.
Using COUNT(DISTINCT salary) which counts unique non-NULL salaries.
3fill in blank
hard

Fix the error in the query to count all rows including those with NULLs in department_id.

SQL
SELECT [1] FROM employees WHERE department_id IS NOT NULL;
Drag options to blanks, or click blank then click option'
ACOUNT(*)
BCOUNT(department_id)
CCOUNT(1)
DCOUNT(DISTINCT department_id)
Attempts:
3 left
💡 Hint
Common Mistakes
Using COUNT(column) which ignores NULLs.
Filtering rows with WHERE department_id IS NOT NULL.
4fill in blank
hard

Fill both blanks to count unique non-NULL values in the email column.

SQL
SELECT [1]([2]) FROM employees;
Drag options to blanks, or click blank then click option'
ACOUNT
Bemail
CDISTINCT
Dsalary
Attempts:
3 left
💡 Hint
Common Mistakes
Using COUNT(email) which counts all non-NULL emails including duplicates.
Using COUNT(DISTINCT salary) instead of email.
5fill in blank
hard

Fill all three blanks to count all rows and count non-NULL phone numbers separately.

SQL
SELECT [1](*) AS total_rows, [2](phone_number) AS phone_count, [3](phone_number) AS unique_phones FROM employees;
Drag options to blanks, or click blank then click option'
ACOUNT
CCOUNT(DISTINCT)
DSUM
Attempts:
3 left
💡 Hint
Common Mistakes
Using SUM instead of COUNT.
Using COUNT(*) for phone_number counts which includes NULLs.