title: MYSQL Sum distinct values after left join
body: <p>I have these tables</p>
  
  <pre><code>/*OrderRows*/
  
  order_id | row_id | article | quantity
      1    |    1   |   pen   |   10
      1    |    2   |scissors |   7
      2    |    3   |  book   |   5 
      3    |    4   |  pen    |   5 
  
  /*Shipments*/
  
  shipment_id | row_id   | quantity_shipped
      1       |     1    |         3
      2       |     1    |         4
      3       |     1    |         3
      4       |     2    |         7
      5       |     3    |         5
      6       |     4    |         5
  </code></pre>
  
  <p>And I need to generate a report to check if an order has been entirely shipped</p>
  
  <p>I wish to use left join instead of subquerys (just to check: is it more efficient?)</p>
  
  <p>If I ask </p>
  
  <pre><code>SELECT
      OrderRows.order_id,
      sum(OrderRows.quantity) as ordered,
      sum(Shipments.quantity_shipped) as shipped
  FROM
      Orders
  LEFT JOIN Shipments ON OrderRows.row_id = Shipments.row_id
  GROUP BY OrderRows.order_id
  </code></pre>
  
  <p>I obviously obtain </p>
  
  <pre><code>order_id | orderered | shipped
      1    |    27    |   17
      2    |    5     |   5
      3    |    5     |   5
  </code></pre>
  
  <p>That's because making left join replicates me the Orders.quantity three times 
   for order_id = 1 (because for order_id = 1 there are 3 shipments)</p>
  
  <p>how can I obtain this without using a subquery?</p>
  
  <pre><code>order_id | orderered | shipped
      1    |    17    |   17
      2    |    5     |   5
      3    |    5     |   5
  </code></pre>