Subject Re: [firebird-support] Optimizing subquery in WHERE ..
Author Harriv
On Tue, Feb 10, 2009 at 4:18 PM, Douglas Tosi <douglasht@...> wrote:
> On Tue, Feb 10, 2009 at 11:48 AM, Harriv <harriv@...> wrote:
>> 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)
>
> Just guessing, but try:
>
> select field1
> from table1
> inner join (SELECT first 2 fieldA from table2 where fieldB = 1) t2 on
> t2.fieldA=table1.field2
>
> This should be faster if fields table1.fieldA and table2.fieldB are indexed.

Yes, that looks like proper solution.

>
> hth,
> --
> Douglas Tosi
> www.sinatica.com
>