Friday, March 30, 2012

Grouping question

I know I'm overlooking something obvious, but I can't seem to find direct help on this in BOL. This should be simple so please forgive my ignorance for not being able to figure this out on my own.

Ok, I have a table that is updated with multiple rows tied to a userid. I want to select out distinct user ids and the max timestamp on any row containing that userid. I cannot seem to get that result set and it's driving me nuts.

e.g. source table:

Userid LastModified

user1 1/1/07
user2 1/1/07
user1 1/2/07
user2 1/3/07

Here's the result set I want to select out that for some reason is eluding me:

Userid LastModified
-
user1 1/2/07
user2 1/3/07

Id be grateful if anyone can lend a hand, thanks.

You should be able to get through this with something like:

select userid,
max (lastModified) as lastModified
from sourceTable
group by userid

|||Thank you, I was absolutely making a mountain out of a molehill and knew it, but just couldn't find my way.

No comments:

Post a Comment