Last active
August 29, 2015 14:25
-
-
Save jonahgeorge/5134b72cd3d7d43e5758 to your computer and use it in GitHub Desktop.
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 "resources".* | |
FROM "resources" | |
INNER JOIN "resources_tags" ON "resources_tags"."resource_id" = "resources"."id" | |
INNER JOIN "tags" ON "tags"."id" = "resources_tags"."tag_id" | |
WHERE ("tags"."id" IN (4,16) | |
AND (SELECT count(*) FROM "tags" WHERE "tags"."id" IN(4,16)) = 2) | |
GROUP BY "resources"."id" | |
ORDER BY "resources"."name" ASC | |
-- Ryan's new method | |
SELECT DISTINCT(ti.resource) FROM adw_stg.tag_ids ti | |
JOIN (SELECT resource, count(id) FROM adw_stg.tag_ids | |
WHERE(id IN(4,16)) | |
GROUP BY resource) sq | |
ON(sq.resource = ti.resource | |
AND sq.count = 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment