Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 6D88E4760FD for ; Thu, 28 Feb 2002 16:40:48 -0500 (EST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id g1SLeKS14961; Thu, 28 Feb 2002 16:40:20 -0500 (EST) To: me@shanewright.co.uk Cc: pgsql-sql@postgresql.org Subject: Re: GROUPing by expressions, and subSELECTs In-reply-to: <200202281830.g1SIU1s11290@fullerruss.dsvr.co.uk> References: <200202281830.g1SIU1s11290@fullerruss.dsvr.co.uk> Comments: In-reply-to Shane Wright message dated "Thu, 28 Feb 2002 18:29:57 +0000" Date: Thu, 28 Feb 2002 16:40:20 -0500 Message-ID: <14958.1014932420@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200202/459 X-Sequence-Number: 6880 Shane Wright 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