| Compare multiple rows in two tables
|
alexelisenko

msg:4180958 | 5:42 am on Aug 3, 2010 (gmt 0) | Hello, I am stumped as to how to build this query, or if its even possible. I has three tables, info, tagmap, tags Table 1: Info id----Title--- 0 | Example 1 | Example2 Table 2: Tagmap id---itemid----tagid--- 0 | 0 | 1 1 | 0 | 2 3 | 1 | 3 4 | 1 | 4 Table 3: Tags id----name---- 0 | Tagone 1 | Tagtwo 3 | Tagthree 4 | Tagfour So as you can see I have a tagmap table that references an info item and a tagid, then a tag table that has the name of the tag in the tagmap, there are 20-30 entries for each info item I need to make a query that will look at all the tags that are associated with an item and return results for other items that have the most tags in common. If anyone has any idea on how to do this please let me know. I have tried comparing just 5 or so tags, on at a time but it does not return results that are relevant enough, so I think I need to compare all tags and return the items that has the most in common. Thank you.
|
redhatlab

msg:4185606 | 10:06 pm on Aug 11, 2010 (gmt 0) | Hi, You can try a query that join all tables at once. Something like this: SELECT a.id, a.title, b.id, b.itemid b.tagid, c.id, c.name FROM info a LEFT JOIN tagmap b ON a.id = b.itemid LEFT JOIN tags c ON c.id = b.tagid
|
|
|