Subject | Optimizing subquery in WHERE .. |
---|---|
Author | Harriv |
Post date | 2009-02-10T13:48:20Z |
Hi,
I've following query (simplified):
SELECT field1
FROM table1
WhERE field2 in (1,2,3,4)
However I'd like to have subquery on where:
SELECT field1
FROM table1
where field2 in (SELECT first 2 fieldA from table2 where fieldB = 1)
However the latter one is very slow, apparantly the subquery is
executed for each row in table1. Can I make it so that the subquery is
only executed once and the result list is used as a criteria?
I've following query (simplified):
SELECT field1
FROM table1
WhERE field2 in (1,2,3,4)
However I'd like to have subquery on where:
SELECT field1
FROM table1
where field2 in (SELECT first 2 fieldA from table2 where fieldB = 1)
However the latter one is very slow, apparantly the subquery is
executed for each row in table1. Can I make it so that the subquery is
only executed once and the result list is used as a criteria?