title: Query SUM for two fields in two different tables
body: <p>I am trying to determine how to do sum fields between two tables.</p>
  
  <p>In table 1, we'll call it gegevens for short, I would have, for example, gegevenID, vertrekdatum, prijs</p>
  
  <p>In table 2, we'll call it fees, I would have , for example, feeID, gegevenID, amount</p>
  
  <p>I want to take and sum the values for prijs based on year(vertrekdatum) from gegevens. </p>
  
  <p>I had tried to do a LEFT JOIN and it worked until there were two records for the same gegevenID in the fee's table., then it doubled the prijs.</p>
  
  <p>Table example:</p>
  
  <pre><code>GEGEVENS
  ----------------------------------
  gegevenID | vertrekdatum | prijs |
  ----------------------------------
  |      1  | 2011-01-01   |1385.88|
  |      2  | 2011-03-01   | 450.26|
  |      3  | 2012-01-01   |2505.10|
  ----------------------------------
  
  FEES
  ----------------------------
  feeID | gegevenID | amount |
  ----------------------------
  |   1 |         2 |   50.00|
  |   2 |         2 |  126.00|
  |   3 |         3 |   50.00|
  ----------------------------
  </code></pre>
  
  <p>The results that I <em>want</em> are</p>
  
  <pre><code>TOTALS
  --------------------------------------------
  | year | SumOfPrijs | SumOfFees |  Total   |
  --------------------------------------------
  | 2011 |  1836.14   |   176.00  |  2012.14 |
  | 2012 |  2505.10   |    50.00  |  2555.10 |
  --------------------------------------------
  </code></pre>
  
  <p>This query resulted in the doubled 'prijs' when it took into account there were two rows in the fees table for one gegevenID.</p>
  
  <pre><code>SELECT sum(prijs) as SumOfPrijs, sum(amount) as SumOfFees, sum(prijs)+sum(amount) AS   
  Total, year(vertrekdatum) as year
  FROM tbl_vluchtgegevens vg
  LEFT JOIN tbl_fees f
  ON f.gegevenID = vg.gegevenID
  
  WHERE vertrekdatum &lt;=NOW()
  GROUP by year(vertrekdatum)
  </code></pre>
  
  <p>Any thoughts would be great.</p>