Re: GROUPing by expressions, and subSELECTs

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: me(at)shanewright(dot)co(dot)uk
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: GROUPing by expressions, and subSELECTs
Date: 2002-02-28 21:40:20
Message-ID: 14958.1014932420@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Shane Wright <me(at)shanewright(dot)co(dot)uk> writes:
> SELECT
> [fields],
> [expression],
> (SELECT * FROM table2 WHERE [expression]) AS mynewfield
> FROM
> table
> GROUP BY
> [expression]

> But, it gives this error:

> ERROR: Sub-SELECT uses un-GROUPed attribute [table].[field] from outer
> query

Yeah, the code is not bright enough to figure out that this could be
considered legitimate. But try this:

SELECT
[fields],
myexpr,
(SELECT * FROM table2 WHERE ss.myexpr) AS mynewfield
FROM
(SELECT [fields],
[expression] as myexpr
FROM table
GROUP BY myexpr) AS ss

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Andy Marden 2002-02-28 21:44:59 Re: Left Outer Join Question
Previous Message Stephan Szabo 2002-02-28 21:27:49 Re: Can't get rid of constraint