Groups | Blog | Home
all groups > sql server new users > may 2007 >

sql server new users : query "last" comment per user


HX
5/31/2007 9:12:45 AM
I'm stuck here - if I use grouping on my userID and select MaxDistinct on
the date/time stamp, how do I pull in the "last comment" from the record,
since it obviously can't be grouped (else ALL the records will show since
all comment fields are different). Help?

This is one thing I tried - obviously doesn't work....

SELECT UserID, MAX(DISTINCT TimeStamp) AS last_time, Comment
FROM user_comments
WHERE (NOT (Comment IS NULL))
GROUP BY TaskID, Name

How do you do this?

HX
5/31/2007 9:30:03 AM
Why do I always finally find something or "get it" AFTER I post? Sorry.

SELECT P.TimeStamp, P.TaskID, P.Name, P.Comment
FROM crane_gwlogin.hpe_comments AS P INNER JOIN
(SELECT TaskID, MAX(TimeStamp) AS
MAX_timestamp
FROM crane_gwlogin.hpe_comments
GROUP BY TaskID) AS X ON X.TaskID = P.TaskID AND
X.MAX_timestamp = P.TimeStamp

Seems to do the trick.


[quoted text, click to view]

AddThis Social Bookmark Button