How to get count of values in a same column in MySQL?

Tech Insights

If you want to get the count of values in a column, it’s pretty much simple to get the required result by executing a simple query. Same applies if you want the total count of rows in a table. You just use COUNT() function of MySQL.

If your table has a column which holds different values for different rows then also you can make use of the same COUNT() function to find the counts of each. This time, you use
COUNT() function along with the GROUP BY clause of MySQL.

Consider the following example table holding the details of students’ promotion status:

id(PK)class_id(FK)student_id(FK)status
111Passed
212Failed
313Passed
424Passed
525Failed
636Passed

To get the count of students for each status, execute the following query:

SELECT status,COUNT(id) FROM student_certificate where class_id=1 GROUP BY status

You will get the result as following:

statuscount
Passed2
Failed1