SQLite 3 reference · Aggregate Functions

SQLite COUNT() Function

Count rows: count(*) counts every row, count(X) counts rows where X isn't NULL, count(DISTINCT X) counts unique values.

SQLite 3

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

count(*)  |  count(X)  |  count(DISTINCT X)

Parameters

ParameterDescription
X A column or expression.

Return value

An integer.

Examples

Three kinds of countTry it yourself
SELECT count(*) AS customers, count(email) AS with_email, count(DISTINCT country) AS countries
FROM customers;

Output

customers | with_email | countries
10 | 9 | 5
Count per groupTry it yourself
SELECT status, count(*) AS orders
FROM orders
GROUP BY status
ORDER BY orders DESC;

Output

status | orders
delivered | 7
shipped | 2
pending | 2
cancelled | 1

In other languages

Was this page helpful?