Skip to content

Instantly share code, notes, and snippets.

@Epigene
Created July 29, 2017 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Epigene/85fa584773b7b1ea2594cfb49dbae95a to your computer and use it in GitHub Desktop.
Save Epigene/85fa584773b7b1ea2594cfb49dbae95a to your computer and use it in GitHub Desktop.
Use SQL!
last_post_ids = Post.select("MAX(id) AS last_post_id").group(:user_id)
last_posts = Post.where(id: last_post_ids).order(created_at: :desc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment