Subject Re: [firebird-support] Re: Old-style left join
Author Kjell Rilbe
ainpoissee wrote:
> Actually RTG.Vahetus is FK and yes, in the second part of the union I
> want those records from RTG for which no matching Vah record exists
> (so RTG.Vahetus is NULL).

Nope. You're thinking in outer join terms. It won't work.

> Casting NULL as datatype as suggested by
> Martijn and Chris seems to work.

It will avoid the error message you got, but you won't get the records
you want.

Generically, this is what you need to do:

select MASTER.F1,
MASTER.F2,
...
MASTER.Fn,
DETAIL.F1,
DETAIL.F2,
...
DETAIL.Fm
from MASTER, DETAIL
where MASTER.PK = DETAIL.FK

union

select MASTER.F1,
MASTER.F2,
...
MASTER.Fn,
cast(null as <whatever>),
cast(null as <whatever>),
...
cast(null as <whatever>)
from MASTER
where not exists (
select 1
from DETAIL
where MASTER.PK = DETAIL.FK
)

Good luck,
Kjell
--
--------------------------------------
Kjell Rilbe
Adressmarknaden AM AB
E-post: kjell.rilbe@...
Telefon: 08-761 06 55
Mobil: 0733-44 24 64