Re: SQL-question (JOIN)

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: pilsl(at)goldfisch(dot)at
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SQL-question (JOIN)
Date: 2003-02-01 01:06:59
Message-ID: Pine.LNX.4.44.0302010200100.789-100000@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

pilsl(at)goldfisch(dot)at writes:

> table1:
> uid | name
> ----+-----
> 1 | bob
> 2 | jim
> 3 | tom
>
> table2:
> uid | name
> ----+-----
> 2 | frank
>
>
> the final join should return:
> uid | name
> ----+-----
> 1 | bob
> 2 | frank
> 3 | tom

select uid, coalesce(table2.name, table1.name) as name from table1 left
join table2 using (uid);

--
Peter Eisentraut peter_e(at)gmx(dot)net

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bruno Wolff III 2003-02-01 01:07:45 Re: SQL-question (JOIN)
Previous Message Curt Sampson 2003-02-01 01:05:19 Re: Status of tablespaces