Subject | Re: [firebird-support] Re: Old-style left join |
---|---|
Author | Ranando King |
Post date | 2005-03-09T14:25:53Z |
Why not just use an *OR* in the where clause of the first select? Seems like
using
...
where (MASTER.PK = DETAIL.FK) or
(not exists
(select 1
from DETAIL
where MASTER.PK = DETAIL.FK))
lets the same thing can be done without needing the union.
R.
"Kjell Rilbe" <kjell.rilbe@...> wrote in message
news:422E14DA.3010608@......
using
...
where (MASTER.PK = DETAIL.FK) or
(not exists
(select 1
from DETAIL
where MASTER.PK = DETAIL.FK))
lets the same thing can be done without needing the union.
R.
"Kjell Rilbe" <kjell.rilbe@...> wrote in message
news:422E14DA.3010608@......
>
> 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