title: MySQL Count values based on multiple columns
body: <p>I have two tables: a 'userlist' that has a 'grade' and 'userID' columns, and a 'login' table that records each time a user is logged in. The login table has a 'userID' column that is associated with the 'userID'. This login table has a row inserted into it each time a user is logged in, so if a user logs in three times, three rows will be added to that table.</p>
  
  <p>I need to run a query that returns how many unique logins happened per grade.</p>
  
  <p>Ie: grade0 = 20 logins, grade1 = 30 logins</p>
  
  <p>I have a feeling it's a combination of DISTINCT, COUNT and GROUP BY, but I can't get it right...</p>
  
  <p>This query is wrong:</p>
  
  <pre><code>SELECT DISTINCT(userID), COUNT(*) as count, u.grade FROM userlist as u, login as l WHERE u.userID = l.userID GROUP BY u.grade, u.userID
  </code></pre>
  
  <p>It is not returning unique logins, but all logins (ie, if a user is logged in twice, he is counted twice).</p>