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 ECBE9D1B55C for ; Fri, 6 Feb 2004 11:43:49 +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 55854-08 for ; Fri, 6 Feb 2004 07:43:47 -0400 (AST) Received: from serwer.skawsoft.com.pl (skawina.eu.org [80.48.213.66]) by svr1.postgresql.org (Postfix) with ESMTP id 72D36D1D17E for ; Fri, 6 Feb 2004 07:43:39 -0400 (AST) Received: from klaster.net (core-1.citynet.pl [80.48.135.14]) by serwer.skawsoft.com.pl (Postfix) with ESMTP id 919A82B3CB; Fri, 6 Feb 2004 12:43:30 +0100 (CET) Message-ID: <40237E7C.7060301@klaster.net> Date: Fri, 06 Feb 2004 12:46:04 +0100 From: Tomasz Myrta User-Agent: Mozilla/5.0 (Windows; U; Win 9x 4.90; pl-PL; rv:1.6b) Gecko/20031208 X-Accept-Language: pl, en-us, en MIME-Version: 1.0 To: Gary Stainburn Cc: pgsql-sql Subject: Re: alias problem on join References: <200402061138.48823.gary.stainburn@ringways.co.uk> In-Reply-To: <200402061138.48823.gary.stainburn@ringways.co.uk> Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/65 X-Sequence-Number: 16756 Dnia 2004-02-06 12:38, Użytkownik Gary Stainburn napisał: > 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; This is an output column alias and it can't be used in where clause. In where clause you have to use original column name and the only aliases you can use there are table aliases. Regards, Tomasz Myrta