title: SQL SELECT with multiple tables and SUM
body: <p>I have used this forum for a while now to find answers to some SQL related questions. Now it's time to ask a question I have tried to figure out for some time now.</p>
  
  <p>I have two tables (product and source).</p>
  
  <p>I would like to create a SQL SELECT to retrieve a list of records from source and one additional record from product (a SUM of price). The table I would like to see should look something like this:</p>
  
  <p>source.source_id | source.location | source.source_name | source.source_description | source.source_date | source.price | SUM(product.price) | SUM(product.price) WHERE product.quantity &lt; 1 (this last column is where I get stuck).</p>
  
  <p>source.location and product.location are linked.</p>
  
  <p>This code works and give the result I want:</p>
  
  <pre><code>SELECT s.source_id
      , s.location
      , s.source_name
      , s.source_description
      , s.source_date
      , s.source_price
      , p2.Total
      , sum(p1.price) as SumProductSold
  FROM source s
  JOIN product p1
      on s.location = p1.location
  JOIN
  (
      SELECT location, sum(price) as Total
      FROM product
      GROUP BY location
  ) p2
      on s.location = p2.location
  WHERE p1.quantity &lt; 1
  GROUP BY s.source_id, s.location, s.source_name
      , s.source_description, s.source_date, s.source_price, p2.Total
  </code></pre>
  
  <p>Thank you bluefeet!!</p>