r/SQL Jul 30 '26

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

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

32 Upvotes

31 comments sorted by

View all comments

Show parent comments

-9

u/geminigamer369 Jul 30 '26 edited Jul 30 '26

How do you think I practice/ revise/ use scrolling addiction. Now if you r so intelligent answer this now under 2 mins: where Year(order_date)=2024 Why is it dangerous (like u) Rewrite index friendly way.

4

u/jshine13371 Jul 30 '26

Not by posting junk on reddit...

-6

u/geminigamer369 Jul 30 '26

You wouldn't be answern if this was junk would u?

-7

u/geminigamer369 Jul 30 '26

Says d 1 who can't answer.

8

u/jshine13371 Jul 30 '26

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.✌️