Skip to content
Justice Tech School

COUNT DISTINCT

COUNT(DISTINCT col) counts unique values. COUNT(*) counts rows and COUNT(col) skips NULLs.

Example
SELECT COUNT(*) AS rows_, COUNT(score) AS scores, COUNT(DISTINCT country) AS countries
FROM students;

Result

rows_ | scores | countries
8     | 7      | 4

Exercise

Count unique values.

COUNT( country)

Quiz Test

Does COUNT(score) count NULLs?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.