I have 2 tables, campaigns and campaign_codes:
campaigns: id, partner_id, status
campaign_codes: id, code, status
I want to get a count of all campaign_c
SELECT c.id AS campaign_id, COUNT(cc.id) AS code_count FROM campaigns c LEFT JOIN campaign_codes cc on cc.campaign_id = c.id AND c.partner_id = 4 AND cc.status = 0 GROUP BY c.id