?
Solved

SQL last user login date

Posted on 2008-11-15
2
Medium Priority
?
664 Views
Last Modified: 2012-05-05
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?
0
Comment
Question by:thehaze
2 Comments
 
LVL 26

Accepted Solution

by:
tigin44 earned 600 total points
ID: 22966747
use aggragate funtion suc the one below.

select user, max(user_login_time)
from Table
group by user
0
 
LVL 9

Expert Comment

by:Ernariash
ID: 22967177
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Loops Section Overview
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question