【问题标题】:Delete from table B where value does not exists in Table A从表 A 中不存在值的表 B 中删除
【发布时间】:2015-01-14 19:17:08
【问题描述】:

我正在尝试在 MySQL 中完成以下工作:

delete from table_b where table_b.token is not found in table_a.token 

解释:

两个表都有一个名为 token 的列。

如果token 中不存在table_b 中的token,我想删除table_b 上的所有记录 table_a 中的列。

【问题讨论】:

  • 谢谢,两位。 mti2935 的建议效果很好。

标签: mysql


【解决方案1】:

使用子查询:

delete from table_b where token not in (select token from table_a)

【讨论】:

    【解决方案2】:

    您可以使用连接

    delete b.*
    from table_b b
    left join table_a a on(b.token = a.token)
    where a.token is null
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-16
      • 2013-03-31
      • 2016-10-25
      • 1970-01-01
      • 2013-10-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多