Re: WHERE IN vs. WHERE OR OR OR
Posted in 1998
Joseph,
Thanks for your response. Unfortunately, the example below is
a little misleading because the the values may not be contiguous.
So I can't use a BETWEEN or equivalent.
I would appear that I'm getting a general "either or" answer from
people I've asked about this. It was my hope that an expert out
there might know.
Dan
Joseph Weinstein wrote:
>
> If your values are contiguous, and preferably if there's
> a unique index with the leading field being x, then it's
> best to do:
>
> select x from y where x between 1 and n
> or
> select x from y where x >= 1 and x <= n>
> > Daniel Kirkdorffer wrote:
> > >
> > > Using JDBC against and Informix database I was wondering if anyone
> > > knew which WHERE clause would be more efficient:
> > >
> > > SELECT x FROM y WHERE x IN (1, 2, 3,..., n)
> > > or
> > > SELECT x FROM y WHERE x = 1 OR x = 2 OR x = 3 OR ... OR x = n
> > > (Where x is a primary key)> > >
> > > Would the choice be the same if n > 100, or even n > 1000?
--
Daniel Kirkdorffer
Sr. Consultant, Syllogistics, LLC.
Email: dan.kirkdorffer 'at' syllogistics 'dot' com
daniel.kirkdorffer 'at' attws 'dot' com
Web: http://www.syllogistics.com/
http://members.aol.com/dankirkd/
Visual Cafe Tips:
http://members.aol.com/dankirkd/vcafe.htm