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)
 Need help with query

Author  Topic 

avi_h
Starting Member

1 Post

Posted - 2007-04-15 : 12:31:56
Hi

I have a table with complex key (userid,actionid,date)
I need to get the latest action (by date)per user. get 1 row for each user + action filtered by the max date for the action

Thanks
Avi

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-04-15 : 14:05:27
[code]Select
userid, actionid
from Tbl t1
where t1.date = (select max(date) from tbl t2 where t2.userid = t1.userid and t2.actionid = t1.actionid)[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -