简体   繁体   中英

Delete from table B where value does not exists in Table A

I am trying to accomplish the following in MySQL:

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

Explanation:

Both tables have a column called 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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM