I need to store a group of “tags” applied to objects. I was thinking of using something along the lines of :

But in order to implement gmail’s “Implicit Social Graph” algorithm (see this question), I need to be able to search for groups of tags that contain one or more specific tags.
So I guess my question is how to get the intersection of two groups of items, in mysql, in the most efficient way ?
find all sets containing one specific tag (given the value):
find all sets containing either of two (or more) specific tags (given the values):
find all sets containing both of exactly two specific tags:
note that the last solution doesn’t generalize, but you could conceivably build a generalized algorithm to generate an n-joined sql statement on the fly.
here is one last implementation that does generalize, although i don’t know its performance characteristics compared to the generated-join way (thanks to @ypercube for an excellent enhancement to my initial suggestion):