dongteng2534 2014-08-10 16:42
浏览 52
已采纳

更新第二个表中主表内的类似关键字

I do have two mysql tables where I would like to mark keywords inside the second table that are inside the main table.

e.g.:

main:

labrador
chihuahua
buldog

second

KEYWORD          SIMILAR
labrador puppies 1
red dogs         0
good medicine    1

Is this even possible with one mysql statement? I would try this with PHP, but hope to find a mysql only solution.

Something like:

UPDATE `keywords` 
SET SIMILAR = 1 
WHERE keyword  like (% SELECT KEYWORD FROM second %")

Has anybody an idea if this is doable and could give me a hint? Thank you for any help on this.

  • 写回答

1条回答 默认 最新

  • donglu5047 2014-08-10 16:59
    关注

    You can connect two tables with joins: MySQL Inner Join Tutorial

    UPDATE
        keywords
    INNER JOIN 
        second 
        ON keywords.KEYWORD LIKE '%', second.KEYWORDS ,'%'
    SET
        keywords.SIMILAR = 1
    WHERE
        keywords.SIMILAR = 0;
    

    this query make only an update if the keyword in keywords table similar like keyword in your second table and doesn't yet marked as similar.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码