pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedjoining VIEWs
2+ messages / 2 participants
[nested] [flat]
* joining VIEWs
@ 2006-08-22 16:40 Brian Cox <bcox4982@yahoo.com>
2006-08-22 16:59 ` Re: joining VIEWs Stephan Szabo <sszabo@megazone.bigpanda.com>
0 siblings, 1 reply; 2+ messages in thread
From: Brian Cox @ 2006-08-22 16:40 UTC (permalink / raw)
To: pgsql-sql
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?
Thanks,
Brian Cox
---------------------------------
Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls. Great rates starting at 1ยข/min.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: joining VIEWs
2006-08-22 16:40 joining VIEWs Brian Cox <bcox4982@yahoo.com>
@ 2006-08-22 16:59 ` Stephan Szabo <sszabo@megazone.bigpanda.com>
0 siblings, 0 replies; 2+ messages in thread
From: Stephan Szabo @ 2006-08-22 16:59 UTC (permalink / raw)
To: Brian Cox <bcox4982@yahoo.com>; +Cc: 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.
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2006-08-22 16:59 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-08-22 16:40 joining VIEWs Brian Cox <bcox4982@yahoo.com>
2006-08-22 16:59 ` Stephan Szabo <sszabo@megazone.bigpanda.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox