Skip to content

Instantly share code, notes, and snippets.

@seancribbs
Forked from joshfrench/gist:267367
Created January 2, 2010 03:36
Show Gist options
  • Save seancribbs/267368 to your computer and use it in GitHub Desktop.
Save seancribbs/267368 to your computer and use it in GitHub Desktop.
Author.find_by_sql "SELECT * FROM authors INNER JOIN extensions ON authors.id = extensions.author_id GROUP BY extensions.author_id HAVING COUNT(extensions.author_id) > 0"
# Had to add the :group key to produce a unique set.
# Removing `:include => :extensions` also reduced this from two queries to one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment