Can someone explain the difference between IN and EXISTS and NOT IN
and NOT EXISTS.
Because I have read that EXISTS will work better than IN and NOT EXISTS will work better than NOT IN.
The query i created is follows..
delete from tt_left t
where t.val = 0
and t.text in (select t1.text
from tt_left t1
where t.text = t1.text
and t.resulttext = t1.resulttext
and t.val = 0
and t1.val = 1);
How to convert this to EXISTS?
Is there any other better method?
The optimiser will treat
INandEXISTSthe same (if the IN clause is not a list of constants)That’s because it is a "semi-join"
Likewise,
NOT INandNOT EXISTSwill be usually treated the same. This is an "anti-semi-join". The exception is where you have a NULL in the NOT IN subquery. This causes the NOT IN to always be falseSo, performance wise there is no difference but
EXISTS/NOT EXISTSwill always be correctSee "NOT IN vs. NOT EXISTS vs. LEFT JOIN / IS NULL: Oracle"
And IN vs. JOIN vs. EXISTS: Oracle which has a similar conclusion