I’m trying to remember what the SQL solution is for this type of problem. Let’s say I have the following tables:
tagged_nodes:
nid– Node id. Foreign key.tid– Tag id. Foreign key.tnid– Primary key (irrelevant to the problem at hand).
nodes:
nid– Node id. Primary key.- … – Other columns are irrelevant.
Assuming I have a set of tag ids (tid), I want to return the set of associated nodes (intersection). How do I do this?
So here’s what I’ve come up with:
It’s in PHP since I need it to be dynamic, but it would basically be the following if I needed, say, only 2 tags (
animals,pets).Am I on the right track?