Re: SQL-question (JOIN) - Mailing list pgsql-general

From Bruno Wolff III
Subject Re: SQL-question (JOIN)
Date
Msg-id 20030201010745.GB14084@wolff.to
Whole thread Raw
In response to SQL-question (JOIN)  (pilsl@goldfisch.at)
List 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 by date:

Previous
From: Sean Chittenden
Date:
Subject: Re: Status of tablespaces
Next
From: Peter Eisentraut
Date:
Subject: Re: SQL-question (JOIN)