Count rows with COUNT
Question
How many employees are there? Return one number.
employeesid, name, salary, department_id, manager_id, hired_on
departmentsid, name, city
Your query
Ctrl+Enter to run
Result
Expected result
| employee_count |
|---|
| 12 |
Hint
COUNT(*) counts rows.
Show the solution
solution.sql
Run this code
SELECT COUNT(*) AS employee_count
FROM employees;
Why it works
COUNT(*) is an aggregate function. It turns all the rows into a single row holding the number of rows, here 12.
Common mistake
COUNT(manager_id) would return 8, not 12, because COUNT(column) skips NULL values. Use COUNT(*) to count rows.