title: Calculate sum on the records while joining two tables with a third table
body: <p>I have three tables:</p>
  
  <pre><code>mysql&gt; select * from a;
  +----+---------+
  | ID | Name    |
  +----+---------+
  |  1 | John    |
  |  2 | Alice   |
  +----+---------+
  
  mysql&gt; select * from b;
  +------+------------+----------+
  | UID  | date       | received |
  +------+------------+----------+
  |    1 | 2017-10-02 |        5 |
  |    1 | 2017-09-30 |        1 |
  |    1 | 2017-09-29 |        4 |
  +------+------------+----------+
  
  mysql&gt; select * from c;
  +------+------------+------+
  | UID  | date       | sent |
  +------+------------+------+
  |    1 | 2017-09-25 |    7 |
  |    1 | 2017-09-30 |    2 |
  |    1 | 2017-09-29 |    3 |
  +------+------------+------+
  </code></pre>
  
  <p>If I try to calculate the total number of sent for John, it would be 12. And for received, it would be 10.
  But if I try to join all three tables, the result is weird. Here is my query to join three tables:</p>
  
  <pre><code>mysql&gt; select sum(sent), sum(received) from a
      -&gt; join c on c.UID = a.ID
      -&gt; join b on b.UID = a.ID
      -&gt; where a.ID = 1;
  +-----------+---------------+
  | sum(sent) | sum(received) |
  +-----------+---------------+
  |        36 |            30 |
  +-----------+---------------+
  </code></pre>
  
  <p>But I need correct numbers (12 and 10, respectively). How can I have correct numbers?</p>