Re: SQL-question (JOIN)

Поиск
Список
Период
Сортировка
От Bruno Wolff III
Тема Re: SQL-question (JOIN)
Дата
Msg-id 20030201010745.GB14084@wolff.to
обсуждение исходный текст
Ответ на SQL-question (JOIN)  (pilsl@goldfisch.at)
Список pgsql-general
On Fri, Jan 31, 2003 at 22:20:52 +0100,
  pilsl@goldfisch.at wrote:
> not sure if such question are on-topic here. (where would this
> question be on-topic ?)
>
> I need to join two tables with a logical "if-statement". If for a
> certain row in table1 there is a related row in table2, then take the
> row from table2 else take it from table1. The relation is a simple
> equal on one column.

I think you want something like this:
select coalesce(table2.name,table1.name) from table1 right join table2
  using (uid);

(Warning the above wasn't actually tested for syntax errors. It also assumes
that name is not null in table2.)

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

Предыдущее
От: Sean Chittenden
Дата:
Сообщение: Re: Status of tablespaces
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: SQL-question (JOIN)