SQL How do I query a many-to-many relationship

Viewed 21027

How do I select posts that contain a specific tag if there is a many-to-many relationship between posts and tags?

The problem I am having is that because of the where tag.name = 'xxx', only that tag is selected. I want to select all posts that have the tag specified, together with all of their tags, e.g.,

Post 1 -> tag1, tag2
Post 2 -> tag1, tag3
Post 3 -> tag2, tag3

Currently what I get is:

Post 1 -> tag2 // missing tag1
Post 3 -> tag2 // missing tag3 
1 Answers
Related