Subject | Re: [firebird-support] Nearly the same sub-select but 2 different results... |
---|---|
Author | Arno Brinkman |
Post date | 2004-04-05T07:18:57Z |
Hi,
That meant you can rewrite a IN :
SELECT * FROM TableA
WHERE
TableA.FieldA IN
(SELECT FIRST 1 SubTable.SubField FROM SubTable)
to an EXISTS to see why this happens :
SELECT * FROM TableA
WHERE
EXISTS(SELECT FIRST 1 SubTable.SubField
FROM SubTable WHERE SubTable.SubField = TableA.FieldA)
For every row in TableA the EXISTS with sub-select is executed.
Regards,
Arno Brinkman
ABVisie
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Firebird open source database (based on IB-OE) with many SQL-99 features :
http://www.firebirdsql.org
http://www.firebirdsql.info
http://www.fingerbird.de/
http://www.comunidade-firebird.org/
Support list for Interbase and Firebird users :
firebird-support@yahoogroups.com
Nederlandse firebird nieuwsgroep :
news://80.126.130.81
> Can you tell me why when we use "IN" instead of " = " in a sub-selectCurrently the IN-predicate is internally exactly the same as a EXISTS.
> it returns all the rows and not only matching rows ???
>
> Exemple :
>
> SELECT
>
> NUMVOL, DATEVOL, NUMAVION, IDPILOTE
> from affectation
> where IDPILOTE = (select first :n skip (:n * :p - :n) IDPILOTE from
> pilote)
>
> It works !!! returns 3 rows.
>
> SELECT
>
> NUMVOL, DATEVOL, NUMAVION, IDPILOTE
> from affectation
> where IDPILOTE IN (select first :n skip (:n * :p - :n) IDPILOTE from
> pilote).
>
> Don't work returns all the rows...
That meant you can rewrite a IN :
SELECT * FROM TableA
WHERE
TableA.FieldA IN
(SELECT FIRST 1 SubTable.SubField FROM SubTable)
to an EXISTS to see why this happens :
SELECT * FROM TableA
WHERE
EXISTS(SELECT FIRST 1 SubTable.SubField
FROM SubTable WHERE SubTable.SubField = TableA.FieldA)
For every row in TableA the EXISTS with sub-select is executed.
Regards,
Arno Brinkman
ABVisie
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Firebird open source database (based on IB-OE) with many SQL-99 features :
http://www.firebirdsql.org
http://www.firebirdsql.info
http://www.fingerbird.de/
http://www.comunidade-firebird.org/
Support list for Interbase and Firebird users :
firebird-support@yahoogroups.com
Nederlandse firebird nieuwsgroep :
news://80.126.130.81