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 161F752939 for ; Wed, 6 Jul 2005 07:30:29 -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 54834-04 for ; Wed, 6 Jul 2005 10:30:27 +0000 (GMT) Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by svr1.postgresql.org (Postfix) with ESMTP id 378CC528BE for ; Wed, 6 Jul 2005 07:30:26 -0300 (ADT) Received: from mainbox.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id 3D15840D4D3; Wed, 6 Jul 2005 11:30:22 +0100 (BST) Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id DE3C1FFA7; Wed, 6 Jul 2005 11:30:16 +0100 (BST) Received: from mainbox.archonet.com ([127.0.0.1]) by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 15469-10; Wed, 6 Jul 2005 11:30:12 +0100 (BST) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id B320BFF8B; Wed, 6 Jul 2005 11:30:07 +0100 (BST) Message-ID: <42CBB2AF.2010601@archonet.com> Date: Wed, 06 Jul 2005 11:30:07 +0100 From: Richard Huxton User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Grant Morgan Cc: pgsql-sql@postgresql.org Subject: Re: left joins References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.056 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200507/31 X-Sequence-Number: 22009 Grant Morgan wrote: > 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. You don't. You make the left join, then apply another condition "p.r_order=1". If you want to demonstrate a problem, you'll need to make sure the queries are the same. -- Richard Huxton Archonet Ltd