X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 7BF95D1C984 for ; Mon, 11 Aug 2003 10:24:05 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 78478-04 for ; Mon, 11 Aug 2003 07:22:38 -0300 (ADT) Received: from stan.ringways.co.uk (hub.ringways.co.uk [213.38.87.130]) by svr1.postgresql.org (Postfix) with ESMTP id 5D680D1C4E6 for ; Mon, 11 Aug 2003 07:23:54 -0300 (ADT) Received: from gary.ringways.co.uk ([10.1.1.2]) by stan.ringways.co.uk with esmtp (Exim 3.22 #1) id 19m9ou-0004tb-00 for pgsql-sql@postgresql.org; Mon, 11 Aug 2003 11:22:32 +0100 Content-Type: text/plain; charset="us-ascii" From: Gary Stainburn Organization: Ringways Garages Ltd To: PostgreSQL-sql Subject: sub-sel/group problem Date: Mon, 11 Aug 2003 11:24:07 +0100 User-Agent: KMail/1.4.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200308111124.07832.gary.stainburn@ringways.co.uk> X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests=USER_AGENT_KMAIL X-Spam-Level: X-Archive-Number: 200308/94 X-Sequence-Number: 14710 Hi folks, I don;t know if it's cos it's Monday or what, but I can't see what's wrong here. I've got two tables, turns which holds a turn number, a task, and where appropriate a link to a loco. The select below works but only shows those tasks where a loco is involved.: select r.rtid, concat(r.rcid::text || ' on ' || l.lnumber::text) as task from rides r, loco_dets l where r.rlid = l.lid group by rtid; rtid | task ------+--------------------------------------------- 5 | G on 60007 6 | A on 75014, C on 75014, A on 75029, C on 75029 7 | C on 4277, A on 44767, C on 44767 8 | A on 30926, C on 30926, G on 60532 9 | A on 30926, C on 30926, A on 75014, C on 75014 10 | F on 2392, F on 75029, L on 75029 11 | A on 44767, C on 44767, A on 75029 However, when I tried to change this to using an outer join I'm getting stuck. Can anyone see my stumbling point, which I think is to do with the condition part of the case statement. Do I need to do that in a sub-select first or is there an alternative? =# select r.rtid, -# case when r.rlid > 0 then -# concat(r.rcid::text || ' on ' || l.lnumber::text) -# else -# r.rcid::text -# end as task -# from rides r -# left outer join loco_dets l on r.rlid = l.lid -# group by rtid -# order by rtid -# ; ERROR: Attribute r.rlid must be GROUPed or used in an aggregate function =# -- 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