Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 54FAA476011 for ; Fri, 29 Nov 2002 09:24:35 -0500 (EST) Received: from bast.unixathome.org (bast.unixathome.org [66.11.174.150]) by postgresql.org (Postfix) with ESMTP id 5567B475F66 for ; Fri, 29 Nov 2002 09:24:34 -0500 (EST) Received: from wocker (wocker.unixathome.org [192.168.0.99]) by bast.unixathome.org (Postfix) with ESMTP id C32123F4E; Fri, 29 Nov 2002 09:24:37 -0500 (EST) From: "Dan Langille" To: Gary Stainburn Date: Fri, 29 Nov 2002 09:24:37 -0500 MIME-Version: 1.0 Subject: Re: master-detail relationship and count Cc: pgsql-sql@postgresql.org Message-ID: <3DE73255.29778.E71B8DFA@localhost> References: <200211291051.07175.gary.stainburn@ringways.co.uk> In-reply-to: X-mailer: Pegasus Mail for Windows (v4.02a) Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Content-description: Mail message body X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/439 X-Sequence-Number: 10581 On 29 Nov 2002 at 13:16, Achilleus Mantzios wrote: > On Fri, 29 Nov 2002, Gary Stainburn wrote: > > > As you can see from the extract below, your statement has worked for all > > landmarks that have links, but ignores any landmarks with out links. How can > > I adjust this so that all landmarks are listed, but with a zero count where > > appropriate? > > Then, use LEFT OUTER JOIN ... USING (), > in combination with COALESCE(). > > (read the docs) When it comes to outer joins, this page is quite useful: http://www.postgresql.org/idocs/index.php?explicit-joins.html I was reading it yesterday when improving the speed of some JOINs. The JOIN went from 3440ms to about 18ms when following the advice on that page. I've put the queries and the explain output at http://www.freshports.org/tmp/outer-join.txt. This will be an example of an OUTER JOIN but not the master-detail situation which occurs elsewhere in the database. cheers -- Dan Langille : http://www.langille.org/