Created
August 26, 2012 11:28
-
-
Save chrisboulton/3477746 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
# All posts tagged with tag 1 AND tag 2 | |
# The two on the right side of the condition should match the number of tags you need to match on. | |
# If it was three tags, it would be = 3. | |
SELECT * | |
FROM `posts` | |
WHERE ( | |
SELECT COUNT(1) | |
FROM `postTags` | |
WHERE | |
postTag_post_id = post_id AND | |
postTag_tag_id IN (1, 2) | |
) = 2; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment