IN vs individual queries, performance comparison

Hello,

If I needed to fetch 3 entries from a database, is there a significant
performance difference between the following?

SELECT * FROM JOBS WHERE myCol IN ('val1','val2',val3');

Versus

SELECT * FROM JOBS WHERE myCol ='val1';
SELECT * FROM JOBS WHERE myCol ='val2';
SELECT * FROM JOBS WHERE myCol ='val3';

Many thanks,
Matt.
bennett.matthew [ Do, 20 Juli 2006 00:48 ] [ ID #1398529 ]

Re: IN vs individual queries, performance comparison

bennett.matthew [at] gmail.com wrote:

> Hello,
>
> If I needed to fetch 3 entries from a database, is there a significant
> performance difference between the following?
>
> SELECT * FROM JOBS WHERE myCol IN ('val1','val2',val3');
>
> Versus
>
> SELECT * FROM JOBS WHERE myCol ='val1';
> SELECT * FROM JOBS WHERE myCol ='val2';
> SELECT * FROM JOBS WHERE myCol ='val3';
>
> Many thanks,
> Matt.
>

you are kidding, right? think about what happens during each "individual" query
- what if that table has 500,000 records - which is faster.

Just in case you were also wondering, the "IN" clause is an implicit "OR".
(where a=1 or a=2 or a=3...)


--
Michael Austin.
DBA Consultant
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)
Michael Austin [ So, 23 Juli 2006 20:51 ] [ ID #1401800 ]
Datenbanken » mailing.database.mysql » IN vs individual queries, performance comparison

Vorheriges Thema: update values on inserting duplicate index
Nächstes Thema: mysql 2gb table limit?