MySQL-brug HAR redegørelse for disse opgaver.
Din forespørgsel ville se sådan ud:
SELECT g.group_id, COUNT(m.member_id) AS members
FROM groups AS g
LEFT JOIN group_members AS m USING(group_id)
GROUP BY g.group_id
HAVING members > 4
eksempel når referencer har forskellige navne
SELECT g.id, COUNT(m.member_id) AS members
FROM groups AS g
LEFT JOIN group_members AS m ON g.id = m.group_id
GROUP BY g.id
HAVING members > 4
Sørg også for, at du indstiller indekser i dit databaseskema for nøgler, du bruger i JOINS, da det kan påvirke dit websteds ydeevne.