Created
June 4, 2012 20:04
-
-
Save evizitei/2870544 to your computer and use it in GitHub Desktop.
a useful sql statement to avoid a subquery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self.class.find_by_sql(["SELECT users.* FROM users | |
INNER JOIN connections AS second_degree_connections | |
ON second_degree_connections.target_id = users.id | |
INNER JOIN connections AS first_degree_connections | |
ON first_degree_connections.target_id = second_degree_connections.owner_id | |
WHERE first_degree_connections.owner_id = ?", self.id]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment