Subject Re: [ib-support] How put conditions upon a sub-select field?
Author Helen Borrie
At 02:04 PM 16-04-02 +0000, you wrote:
>Hi, I've a query like this (FB 1.0):
>SELECT PIANO_CONTI.ESERCIZIO_ID,
> PIANO_CONTI.CONDOMINIO_ID,
> PIANO_CONTI.CONTO_ID,
> PIANO_CONTI.DESCRIZIONEDISP,
> (SELECT RIPARTITO FROM PIANO_CONTI SSPC WHERE
> (SSPC.ESERCIZIO_ID=OPC.ESERCIZIO_ID) ) RIP
>FROM PIANO_CONTI OPC
>WHERE RIP='S'
>
>and I get the error "Column does not belong to referenced table" referred
>to the "RIP='S'" part.
>How can I refer to that field? It shown as "RIP" if I run the query, but
>adding the Where clause I get that error.

Move the second WHERE clause up to the sub-select where it belongs:

SELECT PIANO_CONTI.ESERCIZIO_ID,
PIANO_CONTI.CONDOMINIO_ID,
PIANO_CONTI.CONTO_ID,
PIANO_CONTI.DESCRIZIONEDISP,
(SELECT RIPARTITO FROM PIANO_CONTI SSPC WHERE
SSPC.ESERCIZIO_ID=OPC.ESERCIZIO_ID
and SSPC.RIPARTITO = 'S' ) as RIP
FROM PIANO_CONTI OPC

cheers,
H.

All for Open and Open for All
Firebird Open SQL Database · http://firebirdsql.org ·
http://users.tpg.com.au/helebor/
_______________________________________________________