X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 362B211F6C41 for ; Mon, 3 Apr 2006 00:57:34 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 15642-01 for ; Mon, 3 Apr 2006 00:57:32 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id 07B8A11F6C3D for ; Mon, 3 Apr 2006 00:57:31 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id k333vNOk023309 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 2 Apr 2006 21:57:25 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id k333vMnR048885; Sun, 2 Apr 2006 21:57:22 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id k333vMmX048884; Sun, 2 Apr 2006 21:57:22 -0600 (MDT) (envelope-from mfuhr) Date: Sun, 2 Apr 2006 21:57:22 -0600 From: Michael Fuhr To: Paul M Foster Cc: pgsql-sql@postgresql.org Subject: Re: References NULL field Message-ID: <20060403035722.GA48847@winnie.fuhr.org> References: <443099E6.3070101@quillandmouse.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <443099E6.3070101@quillandmouse.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.121 required=5 tests=[AWL=0.121] X-Spam-Score: 0.121 X-Spam-Level: X-Archive-Number: 200604/9 X-Sequence-Number: 24818 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