Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Find greatest date for user login

Author  Topic 

Poppy
Starting Member

5 Posts

Posted - 2006-05-05 : 04:01:28
Hi

I have a table that logs the dates and times when a user logs on. I have a list of about 500 hundred users and I need to find the most recent date for each of them. So far I have the following query:

select * from userlog where userid in ('jen01',
'sanet27','jamie'...etc) (and last log on date was ...)

I need to have a list that looks something like below:

jen01 2006/03/01
sanet27 2006/03/03
jamie 2006/05/05


Thanks for all your help in advance

Kind Regards

The early bird might catch the worm, but the second mouse sure gets the cheese.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-05-05 : 04:03:56
[code]
select userid, max(last_logon_date)
from yourtable
group by userid
[/code]


KH

Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2006-05-05 : 04:04:22
use group by...

select userid,max(datelogon)
from userlog
group by userid
having userid in ('jen01',
'sanet27','jamie'...etc)
(and last log on date was ...) --guess you won't need this unless you want to specify a range?


--------------------
keeping it simple...
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-05-05 : 04:08:10
Also learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Poppy
Starting Member

5 Posts

Posted - 2006-05-05 : 05:02:20
Hi Guys

Thank you all for your prompt response. I really appreciate it.

Kind Regards

The early bird might catch the worm, but the second mouse sure gets the cheese.
Go to Top of Page
   

- Advertisement -