title: SQL sum and group values from two tables
body: <p>I'm trying to group sales data based on a sellers' name. The name is available in another table. My tables look like this:</p>
  
  <p><strong>InvoiceRow:</strong></p>
  
  <pre><code>+-----------+----------+-----+----------+
  | InvoiceNr | Title    | Row |  Amount  |
  +-----------+----------+-----+----------+
  |  1        | Chair    |  1  |  2000.00 |
  |  2        | Sofa     |  1  |  1500.00 |
  |  2        | Cushion  |  2  |  2000.00 |
  |  3        | Lamp     |  1  |  6500.00 |
  |  4        | Table    |  1  |  -500.00 |
  +-----------+----------+-----+----------+
  </code></pre>
  
  <p><strong>InvoiceHead:</strong></p>
  
  <pre><code>+-----------+----------+------------+
  | InvoiceNr | Seller   | Date       |
  +-----------+----------+------------+
  |  1        | Adam     | 2016-01-01 |
  |  2        | Lisa     | 2016-01-04 |
  |  3        | Adam     | 2016-01-08 |
  |  4        | Carl     | 2016-01-17 |
  +-----------+----------+------------+
  </code></pre>
  
  <p><strong>The query that I'm working with currently looks like this:</strong></p>
  
  <pre><code>SELECT SUM(Amount)
  FROM InvoiceRow
  WHERE InvoiceNr IN (
    SELECT InvoiceNr
    FROM InvoiceHead
    WHERE Date &gt;= '2016-01-01' AND Date &lt; '2016-02-01'
  )
  </code></pre>
  
  <p>This works and will sum the values of all rows of all invoices (total sales) in the month of january.</p>
  
  <p><strong>What I want to do is a sales summary grouped by each sellers' name. Something like this:</strong></p>
  
  <pre><code>+----------+------------+
  | Seller   | Amount     |
  +----------+------------+
  | Adam     | 8500.00    |
  | Lisa     | 3500.00    |
  | Carl     | -500.00    |
  +----------+------------+
  </code></pre>
  
  <p>And after that maybe even grouped by month (but that's not part of this question, I'm hoping to be able to figured that out if I solve this).</p>
  
  <p>I've tried all kinds of joins but I end up with a lot of duplicates, and I'm not sure how to SUM and group at the same time. Does anyone know how to do this?</p>