私は2つのテーブルを持っています。
一方のテーブルにあり、もう一方のテーブルにはないIDを知るにはどうすればよいですか?どうすればそれを達成できますか?
そして、そのようなIDをすべて削除したいと思います。
これは非常に簡単です。
delete from t1
using table1 as t1
left outer join table2 as t2
on t1.id = t2.id
where t2.id is null
結合はサブクエリよりも高速であることに注意してください。
このクエリを使用します:
delete from TABLE_A where ID not in (select ID from TABLE_B)
このクエリを使用します:
delete from t1
where id not in
(select t2.id from t2)