Re: SQL-question (JOIN)

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: pilsl(at)goldfisch(dot)at
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SQL-question (JOIN)
Date: 2003-02-01 01:07:45
Message-ID: 20030201010745.GB14084@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Jan 31, 2003 at 22:20:52 +0100,
pilsl(at)goldfisch(dot)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.)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Keary Suska 2003-02-01 01:28:34 Re: For each record in SELECT
Previous Message Peter Eisentraut 2003-02-01 01:06:59 Re: SQL-question (JOIN)