Re: (FAQ?) JOIN condition - 'WHERE NULL = NULL'

From: "Ian Sillitoe" <ian(dot)sillitoe(at)googlemail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: (FAQ?) JOIN condition - 'WHERE NULL = NULL'
Date: 2008-04-02 17:32:56
Message-ID: c6ff42340804021032n31675e13g485cd6a6a6e361d5@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ah - thanks and apologies for not finding those previous discussions. Does
anyone else feel this might be useful as a point on the NULL section of the
FAQ (it certainly would have saved me an afternoon)?

Cheers,

Ian

On Wed, Apr 2, 2008 at 6:24 PM, Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
wrote:

> Ian Sillitoe wrote:
>
> > This is probably a stupid question that has a very quick answer, however
> > it
> > would be great if someone could put me out of my misery...
> >
> > I'm trying to JOIN two tables (well a table and a resultset from a
> > PL/pgsql
> > function) where a joining column can be NULL
> >
> >
> Sounds like you might want something like:
>
> SELECT * FROM tablea INNER JOIN tableb ON (NOT tablea.id IS DISTINCT FROM
> tableb.tablea_id_fk);
>
> which can also be written as:
>
> SELECT * FROM tablea, tableb WHERE NOT tablea.id IS DISTINCT FROM
> tableb.tableid_id_fk ;
>
> There's been lots of recent discussion of IS DISTINCT FROM, which is why
> it comes straight to mind.
>
> If that's not what you meant (by NULL = NULL) then might you be looking
> for an OUTER JOIN ?
>
> --
> Craig Ringer
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alex Solovey 2008-04-02 17:36:58 Problem with planner choosing nested loop
Previous Message Peter Eisentraut 2008-04-02 17:28:16 Re: [GENERAL] SHA1 on postgres 8.3