简体   繁体   English

从表B中删除,其中表A中不存在值

[英]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.

相关问题 从表 B 中删除,其中列值类似于带有通配符的表 a - Delete from table B where column value like table a with wildcards 从表 B 更新表 A 中的列,其中值不存在于 MYSQL 中表 B 的不同结果中 - Update column in Table A from Table B where value does not exist in distinct result from Table B in MYSQL 如何在同一查询中从表 A 和表 B(如果存在)中删除? - How to delete from table A and table B (if exists) in the same query? 如果 B 不包含特定值,如何从表 A 和 B 中删除记录 - How delete records from table A and B, if B does not contain specific value 从表字段与另一个表不匹配的表中删除 - Delete from table where table field does not match another table 删除表B中不存在表B引用的表A记录,然后删除表C - Delete the records of Table A where Table B reference does not exist and followed by Table C 从表A中删除,其中表A中没有子项,表B中没有子项 - Delete from table A where no children exist in table A and no children exist in table B 选择表格A,表格B中的值 - Select form table A where value in table B 如果删除表A中的值,如何将表B中的值(包括表A中的值)更改为0 - How to change table B value(include from table A) to 0 if the value that include from table A get delete 从表A中获取随机结果(如果它存在于表B中并且满足查询中的WHERE语句) - Get random result from table A if it exists in table B and meets the WHERE statement in the query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM