Reputation: 1250
How to find count of multiple columns in a table
create table foo (key1 int(11), key2 int(11) ..)
I would like to do select count() for key1 and count() for key2 from foo in a single query, is it possible?
Upvotes: 0
Views: 75
Reputation: 1269863
If you want to count the distinct values you can do:
select count(distinct key1), count(distinct key2)
from foo;
If you want counts by values, you can use union all
:
select key1, count(*)
from foo
group by key1
union all
select key2, count(*)
from foo
group by key2;
Upvotes: 1