X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 2DCAC9FA436 for ; Tue, 22 Aug 2006 13:59:36 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 03458-07 for ; Tue, 22 Aug 2006 13:59:30 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by postgresql.org (Postfix) with ESMTP id 54DCD9FA3D7 for ; Tue, 22 Aug 2006 13:59:30 -0300 (ADT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 5A502352E4; Tue, 22 Aug 2006 09:59:29 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 587313520F; Tue, 22 Aug 2006 09:59:29 -0700 (PDT) Date: Tue, 22 Aug 2006 09:59:29 -0700 (PDT) From: Stephan Szabo To: Brian Cox Cc: pgsql-sql@postgresql.org Subject: Re: joining VIEWs In-Reply-To: <20060822164004.88034.qmail@web39806.mail.mud.yahoo.com> Message-ID: <20060822095739.L69038@megazone.bigpanda.com> References: <20060822164004.88034.qmail@web39806.mail.mud.yahoo.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.139 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200608/156 X-Sequence-Number: 26114 On Tue, 22 Aug 2006, Brian Cox wrote: > Given a view like: > > create view view1 as > select g.id as UserGroupId, s.uid as UserId, s.time as StartTime from stats s join groups g on g.uid = s.uid > > and a SELECT like: > > select a.UserGroupId,b.UserGroupId from view1 a > full outer join view1 b on b.UserGroupId = a.UserGroupId > WHERE a.StartTime >= '2006-1-1' AND a.StartTime < '2007-1-1' > AND b.StartTime >= '2005-1-1' AND b.StartTime < '2006-1-1'; > > where there are 5695 rows in 2006 and 1 row in 2005, I expected to get > a result set of 5695 rows, but instead got only 1 row (the common row > in the 2 years). This seems contrary to the definition of "full outer > join". Am I missing something? The where clause is applied after the join. If you want to filter the rows before/during the join itself you can use subselects in the from clause or put the additional conditions in the on condition.