Skip to content

Instantly share code, notes, and snippets.

@chrisboulton
Created August 26, 2012 11:28
Show Gist options
  • Save chrisboulton/3477746 to your computer and use it in GitHub Desktop.
Save chrisboulton/3477746 to your computer and use it in GitHub Desktop.
# 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