Multiple tag search in an associative table scheme

hanswurstel

New Member
I'm working with your standard three table tag setup\[code\]item_table item_id item_nametag_table tag_id tag_nametag_map map_id tag_id item_id\[/code\]How this works should be obvious to anyone who has used a similar scheme for their tagging architecture, now, using this scheme I have a scenario in which I need to print the results of the item_table that match multiple tags, meaning they must have each tag presented to match and print the item from the item table, something written theoretically like this\[code\]SELECT i.item_id, i.item_name, t.tag_id, t.tag_name, m.tag_id, m.item_id FROM item_table AS iJOIN tag_table AS t ON t.tag_id = m.tag_idJOIN tag_map AS m ON m.item_id = i.item_idWHERE t.tag_name = 'tag_one'AND t.tag_name = 'tag_two'\[/code\]And the desired output would be something likeitem 1 (because the records for item 1 have assigned both tag_one and tag_two in the tag map)item 2 (ditto)(but not item 3 because it only has tag_one, or none of the tags)Of course I know this wouldn't work, and why, I merely provided the mis-formed example to highlight what I'm trying to accomplish.Thanks in advance for any advice.
 
Back
Top