SQL last user login date

I have a table that logs user logons called user_logon, with fields id, user and user_login_time.

id      user              user_description      user_login_time
1      user_a      user a                  10-10-2008 10:23
2      user_a      user a                  10-10-2008 11:25
3      user_a      user a                  11-10-2008 10:00
4      user_b      user b                  10-10-2008 10:23
5      user_b      user b                  10-10-2008 10:25
6      user_b      user b                  12-10-2008 10:00

I wish to select the last time that each user has logged on. How do I do this?
thehazeAsked:
Who is Participating?
 
tigin44Connect With a Mentor Commented:
use aggragate funtion suc the one below.

select user, max(user_login_time)
from Table
group by user
0
 
ErnariashCommented:
If you need user_description or extradata on your select use a subquery
like...hope it help you
 

SELECT *
FROM user_logon 
WHERE EXISTS ( 
	SELECT 1 FROM
		 (select user, max(user_login_time) Last_login_time
                   from user_logon
                   group by user)  T
      WHERE user_logon.user = T.user 
	    AND Last_login_time=user_logon .user_login_time 
 
)

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.