Re: joining VIEWs

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Brian Cox <bcox4982(at)yahoo(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: joining VIEWs
Date: 2006-08-22 16:59:29
Message-ID: 20060822095739.L69038@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Daniel CAUNE 2006-08-23 01:40:03 SQL92 compliance
Previous Message Brian Cox 2006-08-22 16:40:04 joining VIEWs