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

From Peter Eisentraut
Subject Re: SQL-question (JOIN)
Date
Msg-id Pine.LNX.4.44.0302010200100.789-100000@localhost.localdomain
Whole thread Raw
In response to SQL-question (JOIN)  (pilsl@goldfisch.at)
List pgsql-general
pilsl@goldfisch.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@gmx.net


pgsql-general by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: SQL-question (JOIN)
Next
From: Curt Sampson
Date:
Subject: Re: Status of tablespaces