Re: tricky GROUP BY / JOIN question - Mailing list pgsql-sql

From T E Schmitz
Subject Re: tricky GROUP BY / JOIN question
Date
Msg-id 4190D82A.6040102@numerixtechnology.de
Whole thread Raw
In response to Re: tricky GROUP BY / JOIN question  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
Hello Tom,

Tom Lane wrote:

> T E Schmitz <mailreg@numerixtechnology.de> 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.
> 
> 
> <snip>
> (select name from condition c1 where position = min(condition.position)),
> (select name from condition c2 where position = max(condition.position)),
> <snip>

Thank you, Tom, this worked a treat!

-- 


Regards/Gruß,

Tarlika Elisabeth Schmitz


pgsql-sql by date:

Previous
From: Giulio Orsero
Date:
Subject: Drop all indexes of a table w/o knowing the index names
Next
From: "Andrei Bintintan"
Date:
Subject: upper/lower for german characters