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 6A6555280D for ; Thu, 30 Jun 2005 08:25:54 -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 95111-05 for ; Thu, 30 Jun 2005 11:25:45 +0000 (GMT) Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by svr1.postgresql.org (Postfix) with ESMTP id 866895280C for ; Thu, 30 Jun 2005 08:25:42 -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 5F15D40DF0B; Thu, 30 Jun 2005 12:25:36 +0100 (BST) Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id 583E215ED7; Thu, 30 Jun 2005 12:22:21 +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 01554-01; Thu, 30 Jun 2005 12:22:18 +0100 (BST) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 2393415ED5; Thu, 30 Jun 2005 12:22:18 +0100 (BST) Message-ID: <42C3D5E9.8010007@archonet.com> Date: Thu, 30 Jun 2005 12:22:17 +0100 From: Richard Huxton User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Nick Stone Cc: pgsql-sql@postgresql.org Subject: Re: SQL Query question References: <20050630092944.E94022514BD@smtp.nildram.co.uk> In-Reply-To: <20050630092944.E94022514BD@smtp.nildram.co.uk> Content-Type: text/plain; charset=ISO-8859-1; 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: 200506/374 X-Sequence-Number: 21975 Nick Stone wrote: > Hi > > Whilst I'm not new to SQL I am reasonably new to Postgres and as such I have > a question on the following query: > FROM > "Terms" As tbl1 LEFT JOIN > "SearchStore" As tbl2 ON tbl1."KeywordID" = tbl2."KeywordID" AND > tbl2."StockID" = 1 > Why does the above query work fine and the folowing query not work? And as a > additional kind of spanner in the works I've tried the following on MS SQL > Server and Oracle both of which produce the correct results > FROM > "Terms" As tbl1 LEFT JOIN > "SearchStore" As tbl2 ON tbl1."KeywordID" = tbl2."KeywordID" > WHERE ... > (tbl2."StockID" = 1) Hmm - I'm not sure that MSSQL/Oracle are giving the "right" answer here. I assume the tbl2.stockid test is the issue here, and we apply the test after the join whereas the others push the condition inside the join. I'm inclined to prefer PG's way of doing things, since it means you get what you explicitly asked for (to my point of view anyway). Not sure what the SQL spec says though, and in the end I suppose that's the only way to decide "right". -- Richard Huxton Archonet Ltd