From: Tomasz Myrta <jasiek@klaster.net>
To: Gary Stainburn <gary.stainburn@ringways.co.uk>
Cc: pgsql-sql <pgsql-sql@postgresql.org>
Subject: Re: alias problem on join
Date: Fri, 06 Feb 2004 12:46:04 +0100
Message-ID: <40237E7C.7060301@klaster.net> (raw)
In-Reply-To: <200402061138.48823.gary.stainburn@ringways.co.uk>
References: <200402061138.48823.gary.stainburn@ringways.co.uk>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: jasiek@klaster.net, gary.stainburn@ringways.co.uk
Subject: Re: alias problem on join
In-Reply-To: <40237E7C.7060301@klaster.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox