Introduction

In this tutorial, we want to count the number of unique values of a specific column. In order to do this, we use the COUNT function with the DISTINCT keyword.

We have already created the table student with the following data:

Example 1

We want to count the number of different birth years.

In order to do this, we execute the following SQL statement:

SELECT COUNT(DISTINCT(birthyear))
FROM student;

The following selection is returned:

Example 2

We want to count the number of different birth years for female students.

In order to do this, we execute the following SQL statement:

SELECT COUNT(DISTINCT(birthyear))
FROM student
WHERE gender = 'female';

The following selection is returned:

Conclusion

Congratulations! Now you are one step closer to become an AI Expert. You have seen that it is very easy to count the number of unique values of a specific column. We can simply use the COUNT function with the DISTINCT keyword. Try it yourself!

Instagram

Also check out our Instagram page. We appreciate your like or comment. Feel free to share this post with your friends.