2019-02-23 パフォーマンスがいけてない not exists 相関サブクエリを left join で書き替える select * from table1 t1 where not exists ( select 1 from table2 t2 where t1.id = t2.id -- <- ここ ); 例の如く、適当な SQL だが、サブクエリで外部の値を使用している。これを left join で書き替える。 select * from table1 t1 left join table2 t2 on t1.id = t2.id and t2.id is null; 参考 qiita.com