I’m drawing a huge blank on something I’m sure I’ve done before, and is probably simple.
Alas, I’m going to ask for assistance anyways.
I have 2 tables:
tbl_admins_groups
tbl_admins
I’m pulling a query on the just the admin group table:
SELECT groupid, groupname, groupdesc FROM tbl_admins_groups
And now I’d like to add another column that counts the number of admin records associated to that groupid.
Here’s my attempt:
SELECT g.groupid, g.groupname, g.groupdesc, COUNT(a.adminid) AS `admincount`
FROM `tbl_admins_groups` g, `tbl_admins` a
WHERE g.groupid = a.groupid
AND a.adminstatus = 1
GROUP BY g.groupid
For some reason I’m getting just one result back.
Is my GROUP BY incorrect?
You can get their
COUNTinside subquery and join it withtbl_admins_groups