X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 6CD6AD1B52C for ; Thu, 28 Aug 2003 23:53:19 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 20317-06 for ; Thu, 28 Aug 2003 20:52:51 -0300 (ADT) Received: from p1.selectacast.net (p1.selectacast.net [199.107.233.195]) by svr1.postgresql.org (Postfix) with ESMTP id DFFAAD1B550 for ; Thu, 28 Aug 2003 20:52:47 -0300 (ADT) Received: from selectacast.net (d1 [64.7.9.58]) by p1.selectacast.net (8.11.6/8.9.3) with ESMTP id h7SNqQh29687; Thu, 28 Aug 2003 19:52:28 -0400 Message-ID: <3F4E95B9.30204@selectacast.net> Date: Thu, 28 Aug 2003 19:52:25 -0400 From: Joseph Shraibman Organization: Xtenit, Inc. http://www.xtenit.com User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Stephan Szabo Cc: pgsql-sql@postgresql.org Subject: Re: How to join from two tables at once? References: <20030825201102.T11277-100000@megazone.bigpanda.com> In-Reply-To: <20030825201102.T11277-100000@megazone.bigpanda.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/350 X-Sequence-Number: 14966 Stephan Szabo wrote: > > Probably you want something like: > SELECT u.uid, u.txt, p.val FROM > u INNER JOIN a ON (a.id=u.aid) > LEFT JOIN p ON (p.uid=u.uid AND p.pkey=a.pkey); From the docs: A CROSS JOIN or INNER JOIN is a simple Cartesian product, the same as you get from listing the two items at the top level of FROM. CROSS JOIN is equivalent to INNER JOIN ON (TRUE), that is, no rows are removed by qualification. These join types are just a notational convenience, since they do nothing you couldn't do with plain FROM and WHERE. ... so obviously there *is* something that INNER JOIN can do that regular ANDs can't. But I'm still not clear why one works and the other doesn't.