SELF LEFT OUTER JOIN = SELF JOIN including NULL values

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

SELF LEFT OUTER JOIN = SELF JOIN including NULL values

Julia Jacobson
Hello everybody out there using PostgreSQL,

After having read the official documentation and having done extensive web search, I'm wondering how to perform something like a SELF LEFT OUTER JOIN in PostgreSQL, i.e. a SELF JOIN on a table containing NULL values in one of the columns to join.

Thanks in advance for your help,
Julia

Heute erleben, was morgen Trend wird - das kann man auf der IFA in Berlin. Oder auf arcor.de: Wir stellen Ihnen die wichtigsten News, Trends und Gadgets der IFA vor. Natürlich mit dabei: das brandneue IPTV-Angebot von Vodafone! Alles rund um die Internationale Funkausstellung in Berlin finden Sie hier: http://www.arcor.de/rd/footer.ifa2010

--
Sent via pgsql-general mailing list ([hidden email])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: SELF LEFT OUTER JOIN = SELF JOIN including NULL values

Raymond O'Donnell
On 17/09/2010 17:16, [hidden email] wrote:
> Hello everybody out there using PostgreSQL,
>
> After having read the official documentation and having done
> extensive web search, I'm wondering how to perform something like a
> SELF LEFT OUTER JOIN in PostgreSQL, i.e. a SELF JOIN on a table
> containing NULL values in one of the columns to join.

Something like this? -

select....
from my_table a
left join my_table b on (a.my_column = b.my_column)
...

Would this do it?

Ray.

--
Raymond O'Donnell :: Galway :: Ireland
[hidden email]

--
Sent via pgsql-general mailing list ([hidden email])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: SELF LEFT OUTER JOIN = SELF JOIN including NULL values

Sam Mason
In reply to this post by Julia Jacobson
On Fri, Sep 17, 2010 at 06:16:44PM +0200, [hidden email] wrote:
> Hello everybody out there using PostgreSQL,
>
> After having read the official documentation and having done extensive
> web search, I'm wondering how to perform something like a SELF LEFT
> OUTER JOIN in PostgreSQL, i.e. a SELF JOIN on a table containing NULL
> values in one of the columns to join.

I guess you're looking for the IS NOT DISTINCT FROM operator.  I.e.

  SELECT *
  FROM foo a
    INNER JOIN foo b ON (a.x = b.x AND a.y IS NOT DISTINCT FROM b.y);

If you want a truth table:

  WITH x(v) AS (VALUES (1),(2),(NULL))
  SELECT l.v, r.v, l.v = r.v AS equality,
    l.v IS NOT DISTINCT FROM r.v AS isnotdistinctfrom
  FROM x l, x r;

--
  Sam  http://samason.me.uk/

--
Sent via pgsql-general mailing list ([hidden email])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Loading...