我对两个表有以下问题:
table1有
table2有
我想编写一个sql脚本,删除table1中不符合条件的所有行
table1.uid = table2.id
答案 0 :(得分:1)
delete from table1 t1
where not exists (select 1 from table2 where id = t1.uid)
OR
delete from table1
where uid not in (select id from table2)
答案 1 :(得分:1)
DELETE FROM table1
WHERE NOT EXISTS
( select table2.name
from table2
where table1.uid = table2.id);