X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 26A2C3A3ACB for ; Tue, 9 Nov 2004 14:53:22 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 40648-10 for ; Tue, 9 Nov 2004 14:53:12 +0000 (GMT) Received: from msgdirector2.onetel.net.uk (msgdirector2.onetel.net.uk [212.67.96.149]) by svr1.postgresql.org (Postfix) with ESMTP id 750F73A3BBA for ; Tue, 9 Nov 2004 14:53:12 +0000 (GMT) Received: from bolek.coachhouse (213-78-122-140.friaco.onetel.net.uk [213.78.122.140]) by msgdirector2.onetel.net.uk (MOS 3.4.6-GR) with ESMTP id CAV27321; Tue, 9 Nov 2004 14:53:05 GMT Received: (Exim 3.36) #1 (Debian)) protocol: esmtp id 1CRXFy-0007E9-00 ; Tue, 09 Nov 2004 14:46:02 +0000 Message-ID: <4190D82A.6040102@numerixtechnology.de> Date: Tue, 09 Nov 2004 14:46:02 +0000 From: T E Schmitz Reply-To: mailreg@numerixtechnology.de User-Agent: Mozilla Thunderbird 0.7 (Windows/20040616) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane Cc: pgsql-sql Subject: Re: tricky GROUP BY / JOIN question References: <418DF96C.4090501@numerixtechnology.de> <22995.1099852316@sss.pgh.pa.us> In-Reply-To: <22995.1099852316@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.3 tagged_above=0.0 required=5.0 tests=UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200411/81 X-Sequence-Number: 19400 Hello Tom, Tom Lane wrote: > T E Schmitz writes: > >>This is *almost* what I need: > > >>SELECT >>BRAND.BRAND_NAME, >>MODEL.MODEL_NAME, >>min (ITEM.PRICE),max (ITEM.PRICE) >>*min (CONDITION.POSITION),max (CONDITION.POSITION)* >>FROM ITEM >>left outer join MODEL on MODEL_PK =ITEM.MODEL_FK >>left outer join BRAND on BRAND.BRAND_PK =MODEL.BRAND_FK >>left outer join CONDITION on CONDITION.CONDITION_PK = ITEM.CONDITION_FK >>group by BRAND.BRAND_NAME,MODEL.MODEL_NAME > > >>In the result I don't want min/max(POSITION) but CONDITION.NAME of min >>and max(POSITION) for each MODEL. > > > > (select name from condition c1 where position = min(condition.position)), > (select name from condition c2 where position = max(condition.position)), > Thank you, Tom, this worked a treat! -- Regards/Gruß, Tarlika Elisabeth Schmitz