From: Michael Fuhr <mike@fuhr.org>
To: Paul M Foster <paulf@quillandmouse.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: References NULL field
Date: Sun, 2 Apr 2006 21:57:22 -0600
Message-ID: <20060403035722.GA48847@winnie.fuhr.org> (raw)
In-Reply-To: <443099E6.3070101@quillandmouse.com>
References: <443099E6.3070101@quillandmouse.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: mike@fuhr.org, paulf@quillandmouse.com
Subject: Re: References NULL field
In-Reply-To: <20060403035722.GA48847@winnie.fuhr.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox