title: mysql: combine 3 query in 1 - group by
body: <p>i have a database with 100 users and their login time (for 1 user there are 10000 rows).
  so how can i pick 3 users (by their userid)  and then  get only last time they logged in</p>
  
  <blockquote>
    <p>(id, userid, timestamp)</p>
  </blockquote>
  
  <pre><code>SELECT userid,timestamp FROM users WHERE userid='22'  ORDER BY id DESC LIMIT 1 ;
  SELECT userid,timestamp FROM users WHERE userid='15'  ORDER BY id DESC LIMIT 1 ;
  SELECT userid,timestamp FROM users WHERE userid='42'  ORDER BY id DESC LIMIT 1 ;
  </code></pre>
  
  <p>i tried also <strong>GROUP BY</strong> but is not showing last timestamp for each user</p>
  
  <pre><code>SELECT userid,timestamp FROM users WHERE userid IN (22,15,42)' GROUP BY userid ORDER BY id DESC LIMIT 3 ;
  </code></pre>