Learn SQL Lesson

COUNT Rows

`COUNT` tells you how many rows match a condition. It is one of the fastest ways to answer questions like “How many sales did we make?” or “How many sales came from the West region?”

The most common form is `COUNT(*)`:

SELECT COUNT(*) AS sale_count
FROM sales

`COUNT(*)` counts rows. `COUNT(column_name)` counts only rows where that column is not `NULL`.

You can also add a `WHERE` clause to count only part of a table.

SELECT COUNT(*) AS sale_count
FROM sales
WHERE region = 'West'

`COUNT` is often the first aggregate people learn because it turns many rows into one simple summary value.

Practice challenge

Return the number of East region sales as sale_count.

Open interactive editor