Using MAX value along with other value

Not sure about the title, but the scenario is that I have a table listing the login dates of users to a site:

LoginID (PK)
LoginDate (Timestamp)

With records such as:

1, 2016-02-20, johnsmith
2, 2016-02-19, maryjones
3, 2016-02-18, johnsmith
4, 2016-02-17, maryjones

I know I can use MAX to get the most recent LoginDate, e.g.

MAX (LoginDate) AS LastLoginDate

But is it possible to extract the most recent LoginDate for each username, i.e.

1, 2016-02-20, johnsmith
2, 2016-02-19, maryjones

1 Like

of course – it’s your basic run-of-the-mill GROUP BY…

SELECT LoginUsername , MAX(LoginDate) AS LastLoginDate FROM login_dates GROUP BY LoginUsername


Thank you - that’s pretty painless!

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.