title: MYSQL: COUNT with GROUP BY, LEFT JOIN and WHERE clause doesn't return zero values
body: <p>I'm sure this has a very simple answer, but I can't seem to find it (not sure what to search on!). A standard count / group by query may look like this:</p>
  
  <pre><code>SELECT COUNT(`t2`.`name`) 
  FROM `table_1` `t1` 
      LEFT JOIN `table_2` `t2` ON `t1`.`key_id` = `t2`.`key_id` 
  WHERE `t1`.`another_column` = 123 
  </code></pre>
  
  <p>and this works as expected, returning 0 if no rows are found. However:</p>
  
  <pre><code>SELECT COUNT(`t2`.`name`) 
  FROM `table_1` `t1` 
      LEFT JOIN `table_2` `t2` ON `t1`.`key_id` = `t2`.`key_id` 
  WHERE `t1`.`another_column` = 123 
  GROUP BY `t1`.`any_col` 
  </code></pre>
  
  <p>only works if there is at least one row in table_1 and fails miserably returning an empty result set if there are zero rows. I would really like this to return 0! Anyone enlighten me on this? Beer can be provided in exchange if you are in London ;-)</p>