Re: GROUPing by expressions, and subSELECTs - Mailing list pgsql-sql

From Shane Wright
Subject Re: GROUPing by expressions, and subSELECTs
Date
Msg-id 200203011218.g21CIFi18470@fullerruss.dsvr.co.uk
Whole thread Raw
In response to Re: GROUPing by expressions, and subSELECTs  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
Tom, you're a star!  It took me a minute to work out what you meant, but hte 
whole thing is working a treat now!

Thanks again,

Shane


On Thursday 28 Feb 2002 9:40 pm, Tom Lane wrote:
> Shane Wright <me@shanewright.co.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


pgsql-sql by date:

Previous
From: Alexander Steinert
Date:
Subject: Re: Large Objects
Next
From: Charles Hauser
Date:
Subject: sub SELECT