Easy Aggregates and GROUP BY Employees database

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

Press Run to see your query's result, or Check answer to compare it with the expected result.

Expected result

employee_count
12

Rows can come in any order. Column names do not have to match.

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.

Want to try the query on MySQL or PostgreSQL? Open it in the SQL Online Compiler or SQLite Online.