Query GROUP BY

From: Oleg Lebedev <oleg(dot)lebedev(at)waterford(dot)org>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Query GROUP BY
Date: 2003-01-09 17:55:58
Message-ID: 993DBE5B4D02194382EC8DF8554A527303354D@postoffice.waterford.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have two similar queries. The first one uses an alias in the GROUP BY
clause, which causes an error. The second query uses the actual column
name in the GROUP BY clause and passes.
Note that the other GROUP BY parameter is an alias in both cases. So,
why would GROUPing work for one alias, but not for the other?

Q1 (Fails):
SELECT c.objectid AS charid,
c.charname AS charname,
SUM (num)
FROM speccharacter c
LEFT OUTER JOIN media m
ON m.mediachar = c.objectid
AND m.mediatype = '2'
GROUP BY charid, charname
ORDER BY charname

Q2 (Runs):
SELECT c.objectid AS charid,
c.charname AS charname,
SUM (num)
FROM speccharacter c
LEFT OUTER JOIN media m
ON m.mediachar = c.objectid
AND m.mediatype = '2'
GROUP BY charid, c.charname
ORDER BY charname


*************************************

This email may contain privileged or confidential material intended for the named recipient only.
If you are not the named recipient, delete this message and all attachments.
Any review, copying, printing, disclosure or other use is prohibited.
We reserve the right to monitor email sent through our network.

*************************************

Browse pgsql-general by date

  From Date Subject
Next Message Christoph Dalitz 2003-01-09 18:40:45 Re: Running PostgreSQL on Windows
Previous Message Randal L. Schwartz 2003-01-09 17:36:10 Open Source Development Lab resources