Skip to content

Instantly share code, notes, and snippets.

@benhoskings
Created October 2, 2013 02:51
Show Gist options
  • Save benhoskings/6788475 to your computer and use it in GitHub Desktop.
Save benhoskings/6788475 to your computer and use it in GitHub Desktop.
SELECT DISTINCT comments.id, comments.content_id, comments.created_at -- whatever fields you like
FROM comments
INNER JOIN (
SELECT comments.id, first_value(comments.id)
OVER (PARTITION BY content_id ORDER BY created_at DESC) comment_id
FROM comments
) chosen
ON chosen.comment_id = comments.id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment