pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruno Wolff III <bruno@wolff.to>
To: Octavio Alvarez <alvarezp@alvarezp.ods.org>
Cc: pgsql-sql@postgresql.org
Subject: Re: LEFT JOIN on one and/or another column
Date: Thu, 29 Jan 2004 07:00:41 -0600
Message-ID: <20040129130041.GB17068@wolff.to> (raw)
In-Reply-To: <1533.63.84.67.25.1075350420.squirrel@alvarezp.ods.org>
References: <1533.63.84.67.25.1075350420.squirrel@alvarezp.ods.org>

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.



view thread (2+ messages)

Message-ID: <20040129130041.GB17068@wolff.to>
Permalink:  ../20040129130041.GB17068@wolff.to/
Also on:    postgresql.org/message-id/20040129130041.GB17068@wolff.to

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: bruno@wolff.to, alvarezp@alvarezp.ods.org
  Subject: Re: LEFT JOIN on one and/or another column
  In-Reply-To: <20040129130041.GB17068@wolff.to>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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