title: MySQL - Counting rows and left join problem
body: <p>I have 2 tables, campaigns and campaign_codes:</p>
  
  <p>campaigns: id, partner_id, status</p>
  
  <p>campaign_codes: id, code, status</p>
  
  <p>I want to get a count of all campaign_codes for all campaigns WHERE campaign_codes.status equals 0 OR where there are no campaign_codes records for a campaign.</p>
  
  <p>I have the following SQL, but of course the WHERE statement eliminates those campaigns which have no corresponding records in campaign_codes ( i want those campaigns with zero campaign_codes as well)</p>
  
  <pre><code>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
  WHERE c.partner_id = 4
  AND cc.status = 0
  GROUP BY c.id
  </code></pre>