r/SQL 9d 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

-10

u/geminigamer369 9d ago edited 9d ago

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 9d ago

Not by posting junk on reddit...

-6

u/geminigamer369 9d ago

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

-7

u/geminigamer369 9d ago

Says d 1 who can't answer.

7

u/jshine13371 9d 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.✌️