2つのテーブルで次の問題が発生します。
table1には
- uid
- 名前
table2には
- id
- 名前
条件を満たさないすべての行をtable1から削除するSQLスクリプトを作成したい
table1.uid = table2.id
2つのテーブルで次の問題が発生します。
table1には
table2には
条件を満たさないすべての行をtable1から削除するSQLスクリプトを作成したい
table1.uid = table2.id
delete from table1 t1
where not exists (select 1 from table2 where id = t1.uid)
また
delete from table1
where uid not in (select id from table2)
DELETE FROM table1
WHERE NOT EXISTS
( select table2.name
from table2
where table1.uid = table2.id);