SQL EXISTS 跟IN的研究比對

SQL  EXISTS 跟IN的研究比對

原始SQL

ATable 大概43萬筆 170個col
BTable 大概3萬筆  20個col

select  Code  from ATable
where  exists (select id from BTable where BTable.id = ATable.Code )

select  Code  from ATable
where   Code in  (select id from BTable )


select  Code  from ATable
where not exists (select id from BTable where BTable.id = ATable.Code )

select  Code  from ATable
where   Code not in  (select id from BTable )

兩個表互轉後效能也差不多
in 跟exists 在正向表列的執行計畫差不多 但是在反向的時候(not) 差非常多
開始習慣用exists....