将文章标题与另一个表中列出的标签匹配

时间:2017-11-26 14:17:01

标签: mysql match match-against

我在mysql中需要一个查询,可以在一个表中列出匹配的tag_names,并在另一个表中列出article_title列

tags table
------------
tag_id  tag_name
--------------
1      travel
2      tickets
3      business
4      america
article table
-------------
article_id  article_title
---------   --------------
1           travel tips to america
2           cheap tickets for favorite destinations
3           prices for business class tickets to america
expected output
--------------
article_id tag_id    tag_name
---------- -------   ----------
1           1        travel
1           4        america
2           2        tickets
3           3        business
3           2        tickets
3           4        america

1 个答案:

答案 0 :(得分:0)

按如下方式加入两个表:

SELECT article_id, tag_id, tag_name
FROM tags as t 
LEFT JOIN articles as a
ON t.tag_name LIKE concat('%',a.article_title,'%')