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
 Transact-SQL (2000)
 Most Recent Date

Author  Topic 

ladiaocb
Yak Posting Veteran

57 Posts

Posted - 2005-05-19 : 13:18:35
Need help. I am trying write a query that will return the latest date value. For example i have the following table:

User LoginDate
Tom 2005-03-23 14:28:37.000
Tom 2005-03-24 14:42:11.000
Tom 2005-03-25 14:42:11.000

I want to return the latest date.

Tom 2005-03-25 14:42:11.000

Thanks in advance.

SamC
White Water Yakist

3467 Posts

Posted - 2005-05-19 : 13:34:29
SELECT MAX(LoginDate) As MaxLoginDate FROM MyTable

OR

SELECT TOP 1 LoginDate FROM MyTable ORDER BY LoginDate DESC
Go to Top of Page

ladiaocb
Yak Posting Veteran

57 Posts

Posted - 2005-05-19 : 13:42:26
Sweet that worked great!
Go to Top of Page

ladiaocb
Yak Posting Veteran

57 Posts

Posted - 2005-05-19 : 13:54:57
Ok. Now i have another problem. I have the following table:

User LoginDate
Tom 2005-03-20 14:28:37.000
Tom 2005-03-23 14:28:37.000
Tom 2005-03-24 14:28:37.000
Jim 2005-03-21 14:28:37.000
Jim 2005-03-23 14:28:37.000
Adam 2005-03-22 14:28:37.000
Adam 2005-03-24 14:28:37.000

I need to retrieve the last login date for each user (I.E.

Result:
Tom 2005-03-24 14:28:37.000
Jim 2005-03-23 14:28:37.000
Adam 2005-03-24 14:28:37.000

Please help!
Go to Top of Page

AndyB13
Aged Yak Warrior

583 Posts

Posted - 2005-05-19 : 13:59:51
SELECT User, MAX(LoginDate) As MaxLoginDate
FROM MyTable
GROUP BY User

Beauty is in the eyes of the beerholder
Go to Top of Page

ladiaocb
Yak Posting Veteran

57 Posts

Posted - 2005-05-19 : 14:06:29
Works great!!! THX AGAIN!
Go to Top of Page
   

- Advertisement -