Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 38E8E4768B4 for ; Mon, 6 Jan 2003 13:31:30 -0500 (EST) Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) by postgresql.org (Postfix) with ESMTP id B70E14768A3 for ; Mon, 6 Jan 2003 13:31:29 -0500 (EST) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 572DFD609; Mon, 6 Jan 2003 10:31:29 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 4CE6C5C04; Mon, 6 Jan 2003 10:31:29 -0800 (PST) Date: Mon, 6 Jan 2003 10:31:29 -0800 (PST) From: Stephan Szabo To: Gary Stainburn Cc: Subject: Re: sub-select, view and sum() In-Reply-To: <200301061729.07459.gary.stainburn@ringways.co.uk> Message-ID: <20030106102933.K47795-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/46 X-Sequence-Number: 10911 On Mon, 6 Jan 2003, Gary Stainburn wrote: > create view turn_details as > select t.*, d.sid as dsid, d.sname as dname, > f.sid as fsid, f.sname as fname, > (select sum(r.rmiles) as rmiles from rides r where r.rtid = tid) > as rmiles > from turns t > left outer join staff d on t.tfitter = d.sid > left outer join staff f on t.tccleaner = f.sid > where r.rtid = t.tid > order by tdate; > ERROR: Relation 'r' does not exist Do you really need the outer where r.rtid=t.tid? I would think that the subselect where clause would already handle that for you.