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.
| Author |
Topic |
|
WallyHartshorn
Starting Member
1 Post |
Posted - 2010-06-29 : 11:31:04
|
Suppose you have a table containing 3 non-unique columns: userId, action, actionDate.How could you select the most recent record for each user? For example:Given this data:Joe Eat 5/1/2010Joe Sleep 5/2/2010Erin Jog 5/2/2010Erin Walk 5/3/2010 You would need to get this resultJoe Sleep 5/2/2010Erin Walk 5/3/2010 I'm stuck! Any help would be greatly appreciated! |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-06-29 : 11:43:52
|
| [code]select userId, action, actionDatefrom(select row_number() over(partition by userId order by actionDate desc) as seq, * from TableA) Twhere seq = 1[/code] |
 |
|
|
|
|
|