title: Select one value of column, corresponding with distinct value of other column
body: <pre><code>voucherId   value  balance
     1         100    20
     2         300    120
     3         500    220
  
  orderId   voucherId  ordertouserId
     1         1           1
     2         3           2   
     3         2           1
     4         1           1  
     2         2           2   
  </code></pre>
  
  <p>I have two tables vouchers and orders. I want to</p>
  
  <pre><code>select sum(value)
  from vouchers with distinct orderid
  group by ordertouserId
  </code></pre>
  
  <p>I'm not sure how I can do this.</p>
  
  <p>This query:</p>
  
  <pre><code>select o.ordertouserId, count(o.order_id) as Orders, sum(v.value) as Total_value
  from vouchers v
  join orders o on o.voucher_id = v.voucher_id
  group by o.ordertouserId
  </code></pre>
  
  <p>Gives the result:</p>
  
  <pre><code>ordertouserId  Orders Total_value
   1               3      500   
   2               2      1000
  </code></pre>
  
  <p>But I want to select <code>sum(v.value)</code> corresponding to <code>distinct o.orderId</code> as <code>Total_value</code>.</p>
  
  <p>Desired Result: </p>
  
  <pre><code>ordertouserId  Orders Total_value
   1               3      500   
   2               1      500
  </code></pre>