I have a table in my mysql db that has two columns: group and subgroup. See below.
group, subGroup
grp-A, sub-A
grp-A, sub-A
grp-A, sub-B
grp-B
You must group both columns, group and sub-group, then use the aggregate function COUNT()
.
SELECT
group, subgroup, COUNT(*)
FROM
groups
GROUP BY
group, subgroup
I think you're looking for: SELECT a, b, COUNT(a) FROM tbl GROUP BY a, b
SELECT group,subGroup,COUNT(*) FROM tablename GROUP BY group,subgroup