Re: JOINS...

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: JOINS...
Date: 2003-05-13 10:25:48
Message-ID: 1052821548.18710.53.camel@linda.lfix.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Tue, 2003-05-13 at 08:01, Dani Oderbolz wrote:
> Thats where the OUTER JOIN comes in - but this is - as far as i know-
> not directly supported in Postgres.
> You have to do this:
>
> Select product.name, color.name
> from
> product,
> color
> where product.color_id = color.color_id
> UNION
> Select product.name, 'No color'
> from
> product
> where
> color_id IS NULL;

This advice is out of date. PostgreSQL does indeed support outer joins
(since 7.1, I think).

SELECT product.name, COALESCE(color.name,'No color') FROM product LEFT
OUTER JOIN color ON product.color_id = color.color_id;

--
Oliver Elphick Oliver(dot)Elphick(at)lfix(dot)co(dot)uk
Isle of Wight, UK http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"Watch ye and pray, lest ye enter into temptation. The
spirit truly is ready, but the flesh is weak."
Mark 14:38

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message sandeep bantia 2003-05-13 13:52:01 Query regarding Insert Statement!!!!
Previous Message Dani Oderbolz 2003-05-13 07:01:41 Re: JOINS...