List:General Discussion« Previous MessageNext Message »
From:HMax Date:February 24 2005 4:04pm
Subject:Subquery speed : IN (SELECT ...) versus IN (X, Y, Z, ...)
View as plain text  
Hello list,

We are currently tuning our queries speed and we found out that the
ones using subqueries are quite slower than the 'usual' ones. Here is
an example of a wierd behavior.

We have a city list associated with zipcode, and user can search a
database of people living in a given city. The problem is that a city
can have several zip codes.

Our first request is :
SQL1 = " SELECT zip FROM tblcity WHERE cityname = 'Paris' "

This request actually returns something like 20 results.

The second request list the people living in areas with those zip codes:
SQL2 = " SELECT people FROM tblpeople WHERE zip IN (###) "

In ### we can either put
- A : SQL1
- B :  the list build from a recordset opened on SQL1 which would give
something like : '75000', '75001', '75002', '75003', etc...

Queries speed are 0.16s for A, and 0.05s for B.

Can anybody explain this behavior, and maybe offer some advices on
optimizing our queries.

Thanks

-- 
HMax
Thread
Subquery speed : IN (SELECT ...) versus IN (X, Y, Z, ...)HMax24 Feb
  • Re: Subquery speed : IN (SELECT ...) versus IN (X, Y, Z, ...)Eli24 Feb
    • Re: Subquery speed : IN (SELECT ...) versus IN (X, Y, Z, ...)HMax25 Feb