I have several users posting comments on several blog posts. Users can comment several times in each blog post. I need SQL Query (sql server 2008) to get the latest comment for each user set in BlogPostId.
Let's say that 3 users posted a total of 10 comments on a specific blog post. For Blog Post # 1, User A posted 5 comments, User B posted 2 comments, and User C posted 3 comments.
For a specific BlogPostId (e.g. # 1), how can I get the last comment for each user restricting it to only their last comment (e.g., one comment for the user)?
The final result should contain three lines (e.g..)
(User A) CommentId, BlogPostId, UserId, CommentData
(User B) CommentId, BlogPostId, UserId, CommentData
(User C) CommentId, BlogPostId, UserId, CommentData
source
share