alias problem on join

From: Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk>
To: pgsql-sql <pgsql-sql(at)postgresql(dot)org>
Subject: alias problem on join
Date: 2004-02-06 11:38:48
Message-ID: 200402061138.48823.gary.stainburn@ringways.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tomasz Myrta 2004-02-06 11:46:04 Re: alias problem on join
Previous Message jan bok 2004-02-06 11:33:00 unsubscribe