title: SQL Distinct join with SUM
body: <p>im facing a little issue with sql join</p>
  
  <p>I have 2 tables</p>
  
  <pre><code>*1st table*                  *2nd table*
  Reference   Name             Reference   Amount
  123         Test1            123         52
  145         Test2            232         22
  123         Test3            123         33
  555         Test4            145         44
  123         Test5            656         55
  </code></pre>
  
  <p>I need something like</p>
  
  <pre><code>select distinct(a.reference), sum(b.amount) from 1st a left join 2nd b ON a.Reference = b.Reference group by a.reference
  </code></pre>
  
  <p>this look pretty simple for me, but what it does - it gives me SUM multiple times where reference is 123 so it will give me (52+33)*3</p>
  
  <p>what should I use to get unique SUM's per Reference?</p>
  
  <p>Thx!</p>
  
  <p>edit:</p>
  
  <p>final result should look like</p>
  
  <pre><code>123   85
  145   44
  </code></pre>