pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
LEFT JOIN on one and/or another column
2+ messages / 2 participants
[nested] [flat]

* LEFT JOIN on one and/or another column
@ 2004-01-29 04:27 Octavio Alvarez <alvarezp@alvarezp.ods.org>
  2004-01-29 13:00 ` Re: LEFT JOIN on one and/or another column Bruno Wolff III <bruno@wolff.to>
  0 siblings, 1 reply; 2+ messages in thread

From: Octavio Alvarez @ 2004-01-29 04:27 UTC (permalink / raw)
  To: pgsql-sql


Hi. I have a table with two foreign keys (1 field each), like in

 id                | serial
 ext_key_original  | integer
 ext_key_exception | integer

They mean different things, as one refers to a typical value, and the
other one refers to an exception that applies for that tuple.

Each key references a different table, one with typical data, and one with
exception data.

I'd like to join on the original, except when exception <> NULL, but I
can't quite figure out how to do so.

Can anyone help?

Thanks you. :-)

Octavio.

-- 
Octavio Alvarez.
E-mail: alvarezp@alvarezp.ods.org.

Agradezco que sus correos sean enviados siempre a esta dirección.



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: LEFT JOIN on one and/or another column
  2004-01-29 04:27 LEFT JOIN on one and/or another column Octavio Alvarez <alvarezp@alvarezp.ods.org>
@ 2004-01-29 13:00 ` Bruno Wolff III <bruno@wolff.to>
  0 siblings, 0 replies; 2+ messages in thread

From: Bruno Wolff III @ 2004-01-29 13:00 UTC (permalink / raw)
  To: Octavio Alvarez <alvarezp@alvarezp.ods.org>; +Cc: pgsql-sql

On Wed, Jan 28, 2004 at 20:27:00 -0800,
  Octavio Alvarez <alvarezp@alvarezp.ods.org> wrote:
> 
> Hi. I have a table with two foreign keys (1 field each), like in
> 
>  id                | serial
>  ext_key_original  | integer
>  ext_key_exception | integer
> 
> They mean different things, as one refers to a typical value, and the
> other one refers to an exception that applies for that tuple.
> 
> Each key references a different table, one with typical data, and one with
> exception data.
> 
> I'd like to join on the original, except when exception <> NULL, but I
> can't quite figure out how to do so.

I am not completely sure from your description what exactly you are trying
to do, but it sounds like you can left join your table to the two foreign
key tables and then use coallesce to grab the value from the appropiate
joined table.



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2004-01-29 13:00 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-01-29 04:27 LEFT JOIN on one and/or another column Octavio Alvarez <alvarezp@alvarezp.ods.org>
2004-01-29 13:00 ` Bruno Wolff III <bruno@wolff.to>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox