Created
January 21, 2014 19:28
-
-
Save romanlehnert/8546582 to your computer and use it in GitHub Desktop.
sql query for posts with multiple comment conditions
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
SELECT "posts".* FROM "posts" | |
WHERE | |
"posts"."id" IN | |
(SELECT post_id FROM "posts" | |
INNER JOIN "comments" ON "comments"."post_id" = "posts"."id" | |
WHERE "comments"."title" = 'foo') | |
AND | |
"posts"."id" IN | |
(SELECT post_id FROM "posts" | |
INNER JOIN "comments" ON "comments"."post_id" = "posts"."id" | |
WHERE "comments"."title" = 'bar') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment