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 471D83A42E0 for ; Sun, 7 Nov 2004 10:34:16 +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 52281-02 for ; Sun, 7 Nov 2004 10:34:11 +0000 (GMT) Received: from msgdirector2.onetel.net.uk (msgdirector2.onetel.net.uk [212.67.96.149]) by svr1.postgresql.org (Postfix) with ESMTP id 19F433A42D3 for ; Sun, 7 Nov 2004 10:34:11 +0000 (GMT) Received: from bolek.coachhouse (213-78-97-118.friaco.onetel.net.uk [213.78.97.118]) by msgdirector2.onetel.net.uk (MOS 3.4.6-GR) with ESMTP id CAQ62642; Sun, 7 Nov 2004 10:34:08 GMT Received: (Exim 3.36) #1 (Debian)) protocol: esmtp id 1CQkKD-0006Lz-00 ; Sun, 07 Nov 2004 10:31:09 +0000 Message-ID: <418DF96C.4090501@numerixtechnology.de> Date: Sun, 07 Nov 2004 10:31:08 +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: pgsql-sql Subject: tricky GROUP BY / JOIN question 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/54 X-Sequence-Number: 19373 Hello, I'm sorry I couldn't think up a more precise subject line. I would like to know whether the following can be implemented in SQL: The example below joins 4 tables ITEM, BRAND, MODEL and CONDITION. In human understandable terms: a [secondhand] Item is of a particular Model and Brand. The Items retail at different prices depending on their Condition. Required result set: Brand | Model | Cond | Cond | Price | Price | | min | max | min | max ------------------------------------------- Canon | A1 | Exc | Mint | 139 | 155 Canon | F1N | Exc++| Mint-| 329 | 379 Canon | 24mm | Exc--| Mint+| 99 | 179 Nikon | 50mm | Exc--| Mint+| 109 | 119 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 Problem: Table CONDITION has the columns - NAME varchar(5) - POSITION int2 In the result I don't want min/max(POSITION) but CONDITION.NAME of min and max(POSITION) for each MODEL. Is this possible at all? -- Regards/Gruß, Tarlika Elisabeth Schmitz