Skip to content

Instantly share code, notes, and snippets.

@drobison
Created February 22, 2014 02:31
Show Gist options
  • Select an option

  • Save drobison/9147755 to your computer and use it in GitHub Desktop.

Select an option

Save drobison/9147755 to your computer and use it in GitHub Desktop.
Find latest entry in a group SQL
SELECT p.id
FROM Posts as p
JOIN (
SELECT id
, MAX(date_modified) as ModifiedDate
FROM Posts
GROUP BY user_id
) lastPost ON p.id = lastPost.id
AND p.date_modified = lastPost.ModifiedDate
order by p.user_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment