Skip to content

Instantly share code, notes, and snippets.

@rondy rondy/gist:2026070

Created Mar 13, 2012
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

fabioyamate commented Mar 13, 2012

oh yeah, subselects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.