title: MySQL - How to eliminate duplicated users in a Ranking?
body: <p>I have a Ranking on my site - with 2 Tables: USERS and ANSWERS.</p>
  
  <p>ANSWERS TABLE is:</p>
  
  <pre><code>&gt; ======================
  &gt; QUIZID ----- USERID ---- TOTALPOINTS ---- TYPE1 -- TYPE2 - TOTALTIME
  &gt;   100   ------  22 -------    100      ----- 30 ---- 70 ----  300
  &gt;   100  -------- 45 -------    80      ------ 40 -----40 ----- 280
  &gt;   101 --------- 45 -------    60 ------------30 -----30 ------200
  </code></pre>
  
  <p>TYPE1 and TYPE2 are the points acumulated in different categories of questions (like "Sales" and "Marketing") - and IF we have a DRAW, most points in TYPE1 WIN.. Most in TYPE2 (the full table has 11 types)..</p>
  
  <p>HERE : User 22 Have 100 Points - and User 45 have 140 Points.</p>
  
  <p>You can do more than 1 Answer for each user - because we had lots of questions.</p>
  
  <p>MY PROBLEM:</p>
  
  <p>USER TABLE is:</p>
  
  <pre><code>========================
  USERID ------ NAME
    22   ------ JOHN
    22 -------- JOHN
    22 -------- JOHN
    45 -------- MARK
  =========================
  </code></pre>
  
  <p>Some users was duplicated on the user table. </p>
  
  <p>I'm using this SELECT to create the ranking (TOP 50):</p>
  
  <pre><code>SELECT users.userid, 
         users.name, 
         Sum(totalpoints), 
         Sum(type1), 
         Sum(type2), 
         Min(totaltime) 
  FROM   answers 
         INNER JOIN users 
                 ON users.userid = answers.userid 
  WHERE  totalpoints &gt; 0 
  GROUP  BY users.userid 
  ORDER  BY Sum(totalpoints) DESC, 
            Sum(type1) DESC, 
            Sum(type2) DESC, 
            Min(totaltime) 
  LIMIT  50 
  </code></pre>
  
  <p>But..</p>
  
  <p>I have the folow result:</p>
  
  <pre><code>USERID - NAME - TOTALPOINTS - TYPE1 - TYPE2 - TOTALTIME
   22 ---- JOHN -     300 ----- 90 ----- 210 --   900
   45 ---- MARK ---   140 ----- 70 ----- 70 ----  480
  </code></pre>
  
  <p>USERID 22 is 3x more points because is 3x in USERS TABLE..</p>
  
  <p>There is any way to correct this - without delete the extra users from users table?</p>
  
  <p>(If I delete the users I got the right Ranking.. but I dont correct the problem.. because if tomorrow anyone duplicated again, the problem will return)</p>
  
  <p>tks!!     </p>
  
  <ul>
  <li>I need to ELIMINATE DUPLICATED ROWS. Not Sum. </li>
  </ul>