Intermediate · Lesson 1 of 20

Counting with COUNT

COUNT tells you how many rows match your query.

Count all rows:

SELECT COUNT(*) FROM employees;

Count non-null values in a column:

SELECT COUNT(email) FROM employees;

Count with conditions:

SELECT COUNT(*) FROM employees
WHERE salary > 80000;

COUNT(*) counts all rows, even with NULL values.

Check your understanding

How many employees are in the database?

Examples run on the employees sample database. Open any of them in the playground to experiment.

Practice it on a real question

All Aggregation questions

Practice on your iPhone

Query Dojo for iPhone has 85 interview questions, timed mock interviews and a tile builder, so you can write queries without a keyboard.

Get the app