title: Insert missing rows (with zero values) into table, following a display pattern
body: <p>I'm creating a procedure that loops through the following table to create a report:</p>
  
  <pre><code>INSERT INTO temp_data
  SELECT val_year, val_name, Group_A, Group_B, Group_C, SUM(product_count) AS in_stock
  FROM all_products
  GROUP BY val_year, val_name, Group_A, Group_B, Group_C;
  
  Resulting rows:
  1: 2014, product_a, food, hot, delicious, 50
  2: 2014, product_a, food, hot, fast, 30
  3: 2014, product_a, food, cold, delicious, 10
  4: 2014, product_a, drinks, hot, delicious, 20
  5: 2014, product_a, drinks, cold, delicious, 40
  6: 2014, product_a, drinks, cold, fast, 60
  
  7: 2014, product_b, food, hot, delicious, 70
  ... etc.
  </code></pre>
  
  <p>The table all_products has been previously created through various UNION ALL queries etc.</p>
  
  <p>I need to report these results to my superiors now, but the table looks like it has "missing" values. I need to rebuild that table so that it shows missing groups with a zero value.</p>
  
  <p>I need to display all the values in a certain pattern, this example would be my desired display:</p>
  
  <pre><code>Rows:
  1: 2014, product_a, food, hot, delicious, 50
  2: 2014, product_a, food, hot, fast, 30
  3: 2014, product_a, food, cold, delicious, 10
  4: 2014, product_a, food, cold, fast, 0
  5: 2014, product_a, drinks, hot, delicious, 20
  6: 2014, product_a, drinks, hot, fast, 0
  7: 2014, product_a, drinks, cold, delicious, 40
  8: 2014, product_a, drinks, cold, fast, 60
  
  9: 2014, product_b, food, hot, delicious, 70
  ... etc.
  </code></pre>
  
  <p>Notice row 4 and 6 have been filled to display zero values for products that are not in stock.</p>
  
  <p>Is there any easy (quick) way to fill the missing rows? All I could think of was a huge 200+ lines long FOR LOOP that goes through current groups, checks for group changes and appends missing groups on group change. That approach felt kind of unprofessional.</p>