Re: LEFT JOIN on one and/or another column

Поиск
Список
Период
Сортировка
От Bruno Wolff III
Тема Re: LEFT JOIN on one and/or another column
Дата
Msg-id 20040129130041.GB17068@wolff.to
обсуждение исходный текст
Ответ на LEFT JOIN on one and/or another column  ("Octavio Alvarez" <alvarezp@alvarezp.ods.org>)
Ответы Re: LEFT JOIN on one and/or another column (thanks)
Список 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.


В списке pgsql-sql по дате отправления:

Предыдущее
От: Bruno Wolff III
Дата:
Сообщение: Re: limit 1 and functional indexes
Следующее
От: "Kumar"
Дата:
Сообщение: Re: SQL Query for Top Down fetching of childs