SQL COUNT
Count rows, non-NULL values, or different values.
Syntax
COUNT(*) COUNT(column) COUNT(DISTINCT column)
COUNT(*) counts rows; COUNT(col) skips NULLs; COUNT(DISTINCT col) counts different values.
Example
Query (on the shop database used in the SQL course)
SELECT COUNT(*) AS customers, COUNT(city) AS with_city, COUNT(DISTINCT country) AS countries FROM customers;
Result
| customers | with_city | countries |
|---|---|---|
| 20 | 18 | 4 |
1 row
Related
Learn it step by step in the free lesson Summarising Data, with exercises that check your queries.