[英]Delete from table B where value does not exists in Table A
我正在嘗試在MySQL中完成以下任務:
delete from table_b where table_b.token is not found in table_a.token
說明:
兩個表都有一個稱為token
的列。
我想刪除表-B的所有記錄,如果token
在表-B不在存在token
在表-A列。
您可以使用聯接
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.