Subject Re: problem with multicolumn subselect
Author fabiano_bonin
--- In firebird-support@yahoogroups.com, Pavel Menshchikov
<mpn2001@y...> wrote:
> Hello Jeremy,
>
> WJ> Select min (col1)
> WJ> From table1
> WJ> Where (col2, col3) in
> WJ> (select col4, col5 from table2 where col6 = variable);
>
> I guess in FB it should be
>
> Select min (col1)
> From table1
> Where col2 in
> (select col4 from table2 where col6 = variable) and
> col3 in
> (select col5 from table2 where col6 = variable);
>

Or, preferably:

select
min(col1)
from
table1
where
exists ( select * from table2 where col4 = table1.col2 and col5 =
table1.col3 and col6 = variable )

This way FB will make use of indices if available, and your query will
be much faster.

Regards,

Fabiano.