title: Join two table. One column using SUM
body: <p>I need a little help with a MySQL query.</p>
  
  <p>I have two tables one table is a list of product and one table is a list of warehouses quantity</p>
  
  <p>product:</p>
  
  <pre><code>product_id   product_name
  1            name1
  2            name2
  3            name3
  </code></pre>
  
  <p>warehouse_product</p>
  
  <pre><code>id   warehouse_id   product_id   product_quantity
  1    1              1            15
  2    2              1            30
  3    1              2            100
  4    2              2            30
  5    1              3            20
  6    2              3            40
  </code></pre>
  
  <p>The results Im looking to get from the above data would be</p>
  
  <pre><code>product_id   product_name  product_quantity
  1            name1         45
  2            name2         130
  3            name3         60
  </code></pre>
  
  <p>I've tried many query but it's not working. My query is:</p>
  
  <pre><code>SELECT 
      product_id as product_id, SUM(quantity) as quantity
  FROM
      (SELECT 
          p.product_id as product_id, wp.product_quantity as quantity
      FROM
          product as p
      LEFT JOIN warehouse_product as wp ON p.product_id = wp.product_id
      WHERE
          product_active = 1)
  </code></pre>