Why won't MySQL add these columns up?
<p>I have a reasonably complex query, that I've simplified down here to try and make it understandable.</p>

<p>In the example below, I am trying to obtain a <code>SUM</code> of sales for two different products. When I retrieve the <code>SUM</code>s individually, as per the first two columns, they calculate correctly.</p>

<p><strong>However, when adding the two <code>SUM</code> queries together (in the third column), if product Y has been sold but <em>NOT</em> product X, the value returns as completely blank.</strong></p>

<p>Any ideas why this might be?</p>

<pre><code>SELECT

  (
    SELECT SUM(IFNULL(product_x_sales.price, 0))
    FROM sales AS product_x_sales
    GROUP BY product_x_sales.customer_id
  ) AS "Total Sales of Product X",

  SUM(IFNULL(product_y_sales.price, 0)) AS "Total Sales of Product Y",

  (
    SELECT SUM(IFNULL(product_x_sales.price, 0))
    FROM sales AS product_x_sales
    GROUP BY product_x_sales.customer_id
  ) + (
    SUM(IFNULL(product_y_sales.price, 0))
  ) AS "Total Sales of Products X and Y"

FROM customers

JOIN sales AS product_y_sales ON customers.id = product_y_sales.customer_id

GROUP BY agents.id
</code></pre>