title: SQL LEFT JOIN with COUNT that returns NULL values
body: <p>I have two tables: one that stores the product id and one which stores total sales per product_id and per sale_date</p>
  
  <h2>Table Products</h2>
  
  <pre><code>product_id
  ----------
  1         
  2         
  3         
  </code></pre>
  
  <h2>Table Sales</h2>
  
  <pre><code>product_id |  sale_date | total
  -----------+------------+-------
  1          | 2017-01-01 |   1
  1          | 2017-02-01 |   1
  1          | 2017-03-01 |   1
  </code></pre>
  
  <p>There is no sales total for product 2 and product 3.</p>
  
  <p>I would like to query the sales table in order to get 0 in front of the months where there is no sale for any product id.
  The result I would like to achieve is this:</p>
  
  <pre><code>product_id |  month     | total
  -----------+------------+-------
  1          | 2017-01    |   1
  1          | 2017-02    |   1
  1          | 2017-03    |   1
  2          | 2017-01    |   0
  2          | 2017-02    |   0
  2          | 2017-03    |   0
  3          | 2017-01    |   0
  3          | 2017-02    |   0
  3          | 2017-03    |   0
  </code></pre>
  
  <p>Right now what I do is this:</p>
  
  <pre><code>SELECT DATE_FORMAT(sale_date, "%m-%Y") as month,
         Products.product_id,
         COUNT(Sales.product_id) as total 
  
    FROM products Products 
  
  LEFT OUTER JOIN sales Sales
  
               ON Sales.product_id = Products.product_id 
  
         GROUP BY Products.product_id, month
  </code></pre>
  
  <p>and what I get is:</p>
  
  <pre><code>product_id |  month     | total
  -----------+------------+-------
  1          | 2017-01    |   1
  1          | 2017-02    |   1
  1          | 2017-03    |   1
  2          | NULL       |   0
  3          | NULL       |   0
  </code></pre>
  
  <p>What should I modify to get a row for each month when there is no sale total for any product id? Thank you</p>