title: How to join 3 tables and get sum from result of individual joins?
body: <p><br>
  I have the following scenario:<br>
  Table: <b>users</b> : user_id, username ,...<br>
  Table: <b>login</b>: user_id, login_date, ...<br>
  Table: <b>point</b>: user_id, points, point_time<br>
  Joins will be on the basis of users.user_id with other tables.
  <br>
  Now, I want to get count of all the logins as well as sum of all the points earned by the user.<br>
  Now, when I do:<br></p>
  
  <pre><code>select users.user_id,count(*) from users
  inner join login on users.user_id=login.user_id
  group by users.user_id
  </code></pre>
  
  <p>It returns count as 36(for example).
  Whenever I run:</p>
  
  <pre><code>select users.user_id,count(*),sum(points) from users
  inner join point on users.user_id=point.user_id
  group by users.user_id
  </code></pre>
  
  <p>It returns sum as 400(for example) and count as 2.</p>
  
  <p>But if I combine both the queries:</p>
  
  <pre><code>select users.user_id,count(*),sum(points) from users
  inner join login on users.user_id=login.user_id
  inner join point on users.user_id=point.user_id
  group by users.user_id
  </code></pre>
  
  <p>It returns count as 72 (36 * 2) and sum as 800 (400 *2).
  Twice because of multiple userIds present.<br>
  I tried several things like combining with distincts but nothing seems to work. Please help.<br>Better if it's possible with joins alone. Thanks in advance. I am using mysql with Php.</p>