Re: how to restrict inner results in OUTER JOIN?

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Drew Wilson <amw(at)speakeasy(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: how to restrict inner results in OUTER JOIN?
Date: 2003-05-06 05:11:48
Message-ID: 20030506051148.GD10957@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, May 05, 2003 at 09:40:10PM -0700, Drew Wilson wrote:
> Now, I would like to exclude all rows whose group_id is NOT 1, but
> include the rows whose group_id is NULL.
>
> I thought adding a WHERE clause would get me what I want...
> SELECT * FROM foo f LEFT OUTER JOIN secure_group sg
> ON (f.group_id = sg.group_id) WHERE sg.group_id = 1;

How about:

SELECT * FROM foo f LEFT OUTER JOIN secure_group sg
ON (f.group_id = sg.group_id)
WHERE ( sg.group_id = 1 or sg.group_id IS NULL );

Hope this helps,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> "the West won the world not by the superiority of its ideas or values or
> religion but rather by its superiority in applying organized violence.
> Westerners often forget this fact, non-Westerners never do."
> - Samuel P. Huntington

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message shoaib 2003-05-06 05:41:37 Re: Database server restarting
Previous Message Drew Wilson 2003-05-06 04:40:10 how to restrict inner results in OUTER JOIN?