Re: References NULL field

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Paul M Foster <paulf(at)quillandmouse(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: References NULL field
Date: 2006-04-03 03:57:22
Message-ID: 20060403035722.GA48847@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Sun, Apr 02, 2006 at 11:43:34PM -0400, Paul M Foster wrote:
> I want to do a query (in PHP, FWIW) that returns all the fields in
> registrars, and the contents of any relevant notes records, or null for
> those fields if there is no corresponding record in the notes table. But
> when I do
>
> SELECT * FROM registrars, notes WHERE regname = 'blah'
>
> no matter that I put after the 'blah' (or nothing), I get no results. As
> soon as I add notes into the tables being queried, I get nothing.

The above query does a cross (cartesian) join of registrars and
notes. Since notes is empty the join result is empty. Try an
outer join:

SELECT *
FROM registrars LEFT OUTER JOIN notes USING (note_id)
WHERE regname = 'blah';

--
Michael Fuhr

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Bryce Nesbitt 2006-04-03 21:58:52 Re: group by function, make SQL cleaner?
Previous Message Paul M Foster 2006-04-03 03:43:34 References NULL field