Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IN versus OR

Status
Not open for further replies.

kmfna

MIS
Sep 26, 2003
306
0
0
US
Hello all,

I was curious if someone could tell me when you should use an "IN" statement versus "OR" statements in your where clause, if you just have a list of values (not an "in (select.. from..).

So really I guess the main question is where, roughly, is the performance cutoff? 2 values? 20? 500??

Thank you, in advance!
-Kevin

- "The truth hurts, maybe not as much as jumping on a bicycle with no seat, but it hurts.
 
I'm not 100% sure on this, but I think they are processed the same way. IN just gives you a shorthand kind of way of writing many OR's.

If you are concerned about speed, order your values in the IN clause by number of times you expect them to appear in your table (descending). This will help because SQL will stop comparing as soon as it hits a value in your list.

Hope this helps,

Alex

Ignorance of certain subjects is a great part of wisdom
 
hmm...good idea, if possible I'll try that, but since all of our lists are dynamically created, that could be a little tricky.

Thanks for your input Alex!! Anyone else have any thoughts on this?

-Kevin

- "The truth hurts, maybe not as much as jumping on a bicycle with no seat, but it hurts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top