Re: subselect prob in view

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: subselect prob in view
Date: 2004-06-22 13:56:27
Message-ID: 17154.1087912587@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk> writes:
> The two selects work seperately, but I'm still getting the
> syntax for the combined quiery wrong.

What you've got here reduces to

select co.co_r_id, co.count as com_count, cor.count as com_unseen
from
(select ...) co,
(select ...) cor on co.co_r_id = cor.co_r_id;

which is invalid because "ON something" must be associated with JOIN.
You could write either of

select co.co_r_id, co.count as com_count, cor.count as com_unseen
from
(select ...) co join
(select ...) cor on co.co_r_id = cor.co_r_id;

select co.co_r_id, co.count as com_count, cor.count as com_unseen
from
(select ...) co,
(select ...) cor
where co.co_r_id = cor.co_r_id;

but you can't mix-and-match.

With an inner join there isn't any semantic difference between ON and
WHERE, so it's a matter of taste which to use. But with outer joins
there's a big difference.

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Phil Endecott 2004-06-22 14:05:20 Re: plpgsql - Insert from a record variable?
Previous Message Stephan Szabo 2004-06-22 13:31:22 Re: subselect prob in view