Re: alias problem on join

From: Tomasz Myrta <jasiek(at)klaster(dot)net>
To: Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk>
Cc: pgsql-sql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: alias problem on join
Date: 2004-02-06 11:46:04
Message-ID: 40237E7C.7060301@klaster.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message CoL 2004-02-06 13:56:01 Re: Storing a range of numbers
Previous Message Gary Stainburn 2004-02-06 11:38:48 alias problem on join