X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 6283FD1CCCD for ; Fri, 6 Feb 2004 11:39:54 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 56078-05 for ; Fri, 6 Feb 2004 07:39:53 -0400 (AST) Received: from stan.ringways.co.uk (hub.ringways.co.uk [213.38.87.130]) by svr1.postgresql.org (Postfix) with ESMTP id 17958D1CACC for ; Fri, 6 Feb 2004 07:39:50 -0400 (AST) Received: from gary.ringways.co.uk ([10.1.1.2]) by stan.ringways.co.uk with esmtp (Exim 3.22 #1) id 1Ap4Ic-0002aE-00 for pgsql-sql@postgresql.org; Fri, 06 Feb 2004 11:37:30 +0000 Content-Type: text/plain; charset="us-ascii" From: Gary Stainburn Organization: Ringways Garages Ltd To: pgsql-sql Subject: alias problem on join Date: Fri, 6 Feb 2004 11:38:48 +0000 User-Agent: KMail/1.4.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200402061138.48823.gary.stainburn@ringways.co.uk> X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/64 X-Sequence-Number: 16755 Hi folks, I've got an accounts table and a transactions table and want to do a summary join. If I do: bank=# select aid, aname, aodraft from accounts a bank-# left outer join (select account, sum(amount) as balance bank(# from statement group by account) as s bank-# on s.account = a.aid; I get the results I want, but I need to rename the aid column to 'key' so that I can feed it into a standard routine I have in PHP to build a hash. If I do: bank=# select aid as key, aname, aodraft from accounts a bank-# left outer join (select account, sum(amount) as balance bank(# from statement group by account) as s bank-# on s.account = a.key; I get ERROR: No such attribute or function 'key' Any ideas why? Also, I'm sure I can do this more efficiently as a single select/join, but can't seem to work out why (Friday morning syndrome). Anyone give me a clue? -- 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