Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id BE1064762B7 for ; Mon, 6 Jan 2003 17:30:44 -0500 (EST) Received: from stan.ringways.co.uk (hub.ringways.co.uk [213.38.87.130]) by postgresql.org (Postfix) with ESMTP id 05DCF476280 for ; Mon, 6 Jan 2003 17:30:44 -0500 (EST) Received: from gary.ringways.co.uk ([10.1.1.2]) by stan.ringways.co.uk with esmtp (Exim 3.22 #1) id 18Vfnb-0004Iz-00; Mon, 06 Jan 2003 22:32:47 +0000 Content-Type: text/plain; charset="iso-8859-1" From: Gary Stainburn Organization: Ringways Garages Ltd To: Stephan Szabo Subject: Re: sub-select, view and sum() Date: Mon, 6 Jan 2003 22:29:47 +0000 User-Agent: KMail/1.4.3 Cc: References: <20030106102933.K47795-100000@megazone23.bigpanda.com> In-Reply-To: <20030106102933.K47795-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200301062229.47578.gary.stainburn@ringways.co.uk> X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/47 X-Sequence-Number: 10912 On Monday 06 January 2003 6:31 pm, Stephan Szabo wrote: > 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. Hi Stephan, Thanks for that. That was the problem. I'd left it after trying to use a normal join in an earlier attempt. Gary -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000