Get last login time of each User ID How to get last login time of selected IDs?

Table

|  user_id  |  lastlogin
|  100      |  2016-03-05
|  110      |  2016-03-21
|  100      |  2016-03-29
|  100      |  2016-04-03
|  110      |  2016-04-02


Here is what I need:

|  user_id  |  lastlogin
|  100      |  2016-04-03
|  110      |  2016-04-02


I have tried this:

SELECT DATE_FORMAT(lastlogin, '%d-%b-%Y') AS lastlogin,user_id
FROM last_logins
WHERE user_id IN (
100,110)
GROUP BY user_id
ORDER BY lastlogin DESC


If I use GROUP BY, it shows the old login record of user_id. If I use just ORDER BY it gives perfect results, but with multiple last logins of user_id.
You need a simple MAX:

SELECT DATE_FORMAT(MAX(lastlogin), '%d-%b-%Y') AS lastlogin,
   user_id
FROM last_logins
WHERE user_id IN (100,110)
GROUP BY user_id
ORDER BY MAX(last_logins.lastlogin) DESC


Don't sort by the formatted lastlogin as this is not a date anymore.

Don't alias using an existing column name, this might lead to confusion and well-hidden bugs (the same condition in WHERE and HAVING meaning different things, for example).

See SQL Fiddle by jkavalik