Eugene Ganancial Eugene Ganancial - 1 month ago 7
MySQL Question

How to sum up total rows of count? MySQL

I want to sum up the total rows given by count.
My code goes like this:

select count(*) from violationprofile where Year = 'Second Year' GROUP BY IDNumber;


but it gives me a result of

count(*)

4 ------> cause I have 4 entries of the same IDNumber

1 ------> only 1 entry of an IDNumber

I want a result of 2, because the total rows of count is only 2.
Is it possible? Thanks!

Answer

You can do:

select count(distinct IDNumber)  
from   violationprofile 
where  Year = 'Second Year'