Skip to content

Instantly share code, notes, and snippets.

@rondy
Created March 13, 2012 01:36
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 rondy/2026070 to your computer and use it in GitHub Desktop.
Save rondy/2026070 to your computer and use it in GitHub Desktop.
Article.all(
:select => "articles.id, articles.title, slugs.name",
:joins => "INNER JOIN slugs
ON slugs.sluggable_type = 'Article' AND
slugs.sluggable_id = articles.id AND
slugs.id = (SELECT id
FROM slugs
WHERE slugs.sluggable_type = 'Article' AND
slugs.sluggable_id = articles.id
ORDER BY slugs.created_at DESC
LIMIT 1)")
@fabioyamate
Copy link

oh yeah, subselects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment