X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 450DA5297F for ; Wed, 6 Jul 2005 07:33:08 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 53895-04 for ; Wed, 6 Jul 2005 10:33:06 +0000 (GMT) Received: from smtp.nildram.co.uk (smtp.nildram.co.uk [195.112.4.54]) by svr1.postgresql.org (Postfix) with ESMTP id 743E752973 for ; Wed, 6 Jul 2005 07:33:03 -0300 (ADT) Received: from HYDROGEN (unknown [62.3.216.34]) by smtp.nildram.co.uk (Postfix) with ESMTP id 3C2C424E7A4; Wed, 6 Jul 2005 11:33:03 +0100 (BST) From: "Nick Stone" To: "'Grant Morgan'" , Subject: Re: left joins Date: Wed, 6 Jul 2005 11:33:03 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook, Build 11.0.6353 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 In-Reply-To: thread-index: AcWCEr4VJ1MiNJoIQ8SQIatt1216UAAAwnHA Message-Id: <20050706103303.3C2C424E7A4@smtp.nildram.co.uk> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200507/32 X-Sequence-Number: 22010 I've had exactly yhe same problem - try changing the query to. select count(*) from h left join p using (r,pos) and p.r_order=1 where h.tn > 20 and h.tn < 30 I think that should do it - the syntax you used would work in Oracle and MS SQL but there's a subtle difference with the way Postgres works that means that any NULLS in the right hand side of the join will be ignored effectively making it an inner join Hope this helps Nick -----Original Message----- From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Grant Morgan Sent: 06 July 2005 11:02 To: pgsql-sql@postgresql.org Subject: [SQL] left joins I am having a problem with left joins in Postgresql.(probably my misunderstanding of left joins) My first Query returns 70,000 select count(*) from h where h.tn > 20 and h.tn < 30 my left join returns only 34,000 select count(*) from h left join p using (r,pos) where h.tn > 20 and h.tn < 30 and p.r_order=1 since it is a left join I though I should get a number no smaller in the left join than the original unjoined query. It seems to be acting like an inner join. Both of these are tables not views and both have hash indices on r column. I have tried left joins, right joins , and both using and on , nothing seems make a difference. Questions 1)should a left join return atleast as many rows as the unjoined left table? 2)am I doing something wrong above? 3)If am not doing anything wrong is this postgresql problem and is there a work around? Cheers, Grant ---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org