2012-10-15 74 views
0

刪除某些行我有兩個表如下問題:如何PLSQL

表1有

  • UID

表2具有

  • ID

我想編寫SQL腳本,刪除從表1中的所有行不符合條件

table1.uid = table2.id 
+0

唐別忘了接受最好的答案。 – jncraton

回答

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
DELETE FROM table1 
WHERE NOT EXISTS 
(select table2.name 
    from table2 
    where table1.uid = table2.id);