Combining COUNT and DISTINCT
Count unique values.
Syntax
sql
1SELECT COUNT(DISTINCT column) FROM table;Example
How many different courses?
sql
1SELECT COUNT(DISTINCT course) FROM students;Result
| COUNT(DISTINCT course) |
|---|
| 5 |
Comparison
sql
1-- Total rows
2SELECT COUNT(*) FROM students; -- 25
3
4-- Unique courses
5SELECT COUNT(DISTINCT course) FROM students; -- 5