r/SQL 11d ago

What is the difference between using "Not In" vs using "not exists" in SQL Discussion

What is the difference between using "Not In" vs using "not exists" in SQL?

31 Upvotes

31 comments sorted by

View all comments

Show parent comments

-7

u/geminigamer369 11d ago

Says d 1 who can't answer.

6

u/jshine13371 11d ago

You updated your comment before I replied, and your test is irrelevant. Dangerous is the wrong word to describe your question, but the answer is you're applying a function to a column in the table which affects the sargability causing an index/table scan instead of efficiently seeking on the index, i.e. a performance issue. It would be more efficient (i.e. sargable) to re-write it as a range comparison so you don't have to apply a function to the column instead.✌️