【问题标题】:Mysql compare and update table if there is a matchMysql比较并更新表,如果有匹配
【发布时间】:2017-06-03 04:32:05
【问题描述】:

我有三个表,结构如下:

产品表:“product_id”、“name”、“hashtags”(用|分隔)

标签表: "tag_id", "tag_name"

标签关系表: "tag_id", "product_id"

这是我的问题: 如何将 product 表 中的“hashtags”(以 | 分隔)与 tags 表 中的“tag_name”进行比较,如果匹配,请添加以下“product_id”和“tag_id”到标签关系表?

【问题讨论】:

    标签: mysql join


    【解决方案1】:

    您可以使用以下查询

    insert into tag_relation_table(tag_id,product_id)
    select tbl2.tag_id, tbl1.product_id 
    from product_table tbl1
    inner join tags_table tbl2 on locate(tbl2.tag_name,tbl1.hashtags)>0
    

    如果成功请告诉我!

    【讨论】:

    • 谢谢!像魅力一样工作!
    • @Gremlin,不客气。如果有效,请接受答案。
    猜你喜欢
    • 1970-01-01
    • 2017-09-25
    • 1970-01-01
    • 1970-01-01
    • 2011-02-15
    • 2020-10-04
    • 2020-07-06
    • 2022-12-02
    • 1970-01-01
    相关资源
    最近更新 更多