如何删除plsql中的某些行

时间:2012-10-15 11:51:29

标签: sql plsql delete-row

我对两个表有以下问题:

table1有

  • UID
  • 名称

table2有

  • ID
  • 名称

我想编写一个sql脚本,删除table1中不符合条件的所有行

table1.uid = table2.id

2 个答案:

答案 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);