title: Displaying rows with count 0 in MySQL using COUNT and GROUP BY
body: <p>I have two tables, Subject and Content, where Content references Subject with foreign key. I want to display how many times each subject appears in Content table (0, if it does not appear). But the query below only gives me the rows with count > 0 and ignores the others:</p>
  
  <pre><code>SELECT Subject.id, Subject.name, COUNT(Content.subject_id) AS `count`
  FROM Subject LEFT JOIN Content
  ON Subject.id = Content.subject_id
  WHERE type = @type
  GROUP BY Subject.id;
  </code></pre>
  
  <p>I checked and tried to follow <a href="https://stackoverflow.com/questions/3855678/mysql-include-zero-rows-when-using-count-with-group-by">this</a>, <a href="https://stackoverflow.com/questions/1478384/mysql-select-count-group-by-not-returning-rows-where-the-count-is-zero">this</a> and <a href="https://stackoverflow.com/questions/743456/displaying-rows-with-count-0-with-mysql-group-by">this</a> post but for some reason the code above does not work.</p>
  
  <p>Any ideas?</p>
  
  <p>Edit:
  the type field is in the Content table and that was causing the the problem as "Will A" pointed out</p>