Very Easy
Count unique names
Count the number of unique first names in the students
table.
SCHEMA
students
+------------+------------+-----------+-----+------------+
| student_id | first_name | last_name | age | class_code |
+------------+------------+-----------+-----+------------+
| 1 | Mike | Chaplin | 12 | 7A |
| 2 | Emily | Jackson | 12 | 7A |
| 3 | Robert | Jackson | 12 | 7A |
| ... | ... | ... | ... | ... |
+------------+------------+-----------+-----+------------+
EXPECTED OUTPUT
+------------------------+
| num_unique_first_names |
+------------------------+
| 60 |
+------------------------+
You can use COUNT(DISTINCT col_name)
to count the number of distinct/unique values in a col col_name
.
SELECT COUNT(DISTINCT first_name) FROM students