Eugene Ganancial Eugene Ganancial - 1 year ago 68
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


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 Source

You can do:

select count(distinct IDNumber)  
from   violationprofile 
where  Year = 'Second Year' 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download