[英]Delete from table B where value does not exists in Table A
I am trying to accomplish the following in MySQL: 我正在尝试在MySQL中完成以下任务:
delete from table_b where table_b.token is not found in table_a.token
Explanation: 说明:
Both tables have a column called token
. 两个表都有一个称为
token
的列。
I want to delete all records on table_b if token
in table_b does not exist in the token
column in table_a. 我想删除表-B的所有记录,如果
token
在表-B不在存在token
在表-A列。
You can use a join 您可以使用联接
delete b.*
from table_b b
left join table_a a on(b.token = a.token)
where a.token is null
使用子查询:
delete from table_b where token not in (select token from table_a)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.