I have a table with two columns, blog post ids and tag ids. A blog post can have several tags like it’s a post about “New York” and “Soho”. Let’s say I want to find all the blog posts that have BOTH tag id 1 and 2, how do I do that?
blogPostToTags
=============================
id |tagId
-----------------------------
1 |1
1 |2
2 |1
3 |2
UPDATE:
I’ve tried the following:
SELECT id FROM blogPostToTags WHERE tagId = 1 AND tagId = 2
and
SELECT id FROM blogPostToTags WHERE tagId = 1 OR tagId = 2
neither work…
Use double
JOIN.