我有一个像这样的简单数据库:
table "contents":
--------------------------
CID | contentName
1 | Watermelon
table "tags":
--------------------------
TID | tagName | tagKeywords
77 | Fruit | Fruit, fruits
99 | Nature | nature, green, mother earth
table "associations":
--------------------------
CID | TID
1 | 77
1 | 99
我应该如何编写一个在表“内容”中搜索的选择,其中每一行都继承任何关联标签的关键字?
例如,如果我搜索“fruit”和“green”,全文搜索结果应该更相关,因为匹配两个标签
最佳答案
我认为这更符合您的需求:
SELECT c.contentName, GROUP_CONCAT(tagkeywords separator ',')
FROM contents c
INNER JOIN associations a ON a.CID = c.CID
INNER JOIN tags t ON t.TID = a.TID
GROUP BY c.contentName;
我刚刚测试了它,得到以下结果:
contentName GROUP_CONCAT(tagkeywords separator ',')
----------- ---------------------------------------
Watermelon Fruit, fruits,nature,green,mother earth
关于php - 在表和链接表上搜索全文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9827678/