Re: If table A value IS NULL then table B

From: Marco Lazzeri <marcomail(at)noze(dot)it>
To: vhikida(at)inreach(dot)com
Cc: Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl>, Martín Marqués <martin(at)bugs(dot)unl(dot)edu(dot)ar>, pgsql-general(at)postgresql(dot)org
Subject: Re: If table A value IS NULL then table B
Date: 2004-01-24 14:07:43
Message-ID: 1074953262.2560.2.camel@macbeth.intranet.noze.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Yes, id_other_table IS a foreign key to id and usually I've got records
in each table.

Thanks to all of you!

Il ven, 2004-01-23 alle 21:45, vhikida(at)inreach(dot)com ha scritto:
> As for the outer join, I think that the problem was ambiguous.
>
> Is id_other_table a foreign key to id? Is there at most one row in each
> table?
>
> > On Fri, Jan 23, 2004 at 05:15:56PM -0300, Martín Marqués wrote:
> >> Mensaje citado por Marco Lazzeri <marcomail(at)noze(dot)it>:
> >>
> >> > I want to write a query on table 'main' that if 'id_other_table' is
> >> null
> >> > returns value from itself, from table 'other' otherwise.
> >>
> >> SELECT CASE WHEN id_other_table IS NULL THEN id_other_table
> >> ELSE id
> >> FROM main,other
> >
> > What about COALESCE?
> >
> > SELECT COALESCE(id_other_table, id) FROM main, other WHERE ...
> >
> > (Also probably an OUTER JOIN is needed -- see
> > http://www.varlena.com/GeneralBits/56.php)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Doug McNaught 2004-01-24 14:11:39 Re: Touch row ?
Previous Message Lee Harr 2004-01-24 13:29:59 Re: force drop of database others are accessing