In MySQL, there is a way to count several rows with different non-NULL expr values, which means this statement can fetch us the distinct count of the rows present in the table.
Syntax
COUNT(distinct(expr..))
Example: Count with Distinct in MySQL
Let us see a real-time example of how we can perform the count of distinct rows in a table. For this, we will be using a table called 'course_details.'
So here we can see that the courses with the same ID have different courses. We will try to get the count of distinct courses present in this table.
SELECT course_ID,COUNT(distinct(course))
FROM course_detailss
GROUP BY course_ID;
- We can see here that the count of courses for two IDs has different courses, and using this statement, we can quickly point out the count of the distinct courses.
Conclusion:
So this is how we can use the count of distinct statements to identify an extensive database with a complicated number of distinct rows.
- Log in to post comments