I have three tables:
posts (id, content)
posts_tags (posts_id, tags_id)
tags (id, tag)
How do I select all posts that have (at least) 2 specific tags (lets say tags with id 1 and 2)?
For example, posts table:
id content
---- -------
1 post1
2 post2
3 post3
tags table:
id tag
---- ------
1 tag1
2 tag2
3 tag3
posts_tags table:
posts_id tags_id
---------- ---------
1 1
1 2
2 1
3 1
3 2
3 3
I then expect the following result:
id content
---- ---------
1 post1
3 post3
Post with ID 3 (since it has tags 1, 2, and 3) and post with id 1 (since it has tags with id 1, and 2) but not post 2 since it doesn't have tag with id 2.
Assume I can not change the table structure.