Skip to content

Instantly share code, notes, and snippets.

@lettergram
Last active May 18, 2019 01:06
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 lettergram/35ed869e64fdfa7030f0ca0ade025782 to your computer and use it in GitHub Desktop.
Save lettergram/35ed869e64fdfa7030f0ca0ade025782 to your computer and use it in GitHub Desktop.
Create a subquery in Rails using Active Record
query = select(:author, :created_at)
.from(
where("created_at >= ?", Date.today - 6.months)
.order(created_at: :desc)
.limit(100)
).order(author: :asc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment