From: | John Sidney-Woollett <johnsw(at)wardbrook(dot)com> |
---|---|
To: | Fip <Filippo(dot)Bernante(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: grouping excluding some text results |
Date: | 2006-10-26 17:16:26 |
Message-ID: | 4540ED6A.9000104@wardbrook.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Off the top of my head (and not sure how optimized)...
select t1.id, t1.score, t1.description
from scoretable t1, (
select id, max(score) as score
from scoretable
group by id
) as t2
where t1.id = t2.id
and t1.score = t2.score
order by t1.id
If you get duplicated rows back, then try using
select distinct t1.id, t1.score, t1.description ...
instead.
Hope that helps.
John
Fip wrote:
> Hi,
>
> ho can I select some one restult for type, excluding the rest?
> I have something like, as result of a join:
>
> | ID | score | description |
> -----------------------------------------------------------------
> MG01 56 "textual description1..."
> MG02 47 "another text ..."
> MG02 55 "textual description, text...." <----
> note this
> MG02 55 "textual description, text...." <----
> note this
> MG01 35 "this is a different text...."
> MG02 61 "random chars..."
> (...)
>
>
> I know that is possible selecting by grouping if I use an aggregate
> function:
>> select ID,max(score) by table group by ID
> but I want the description too, only one description, and I have a very
> large dataset, I cannot cycle with more subselections, this require too
> much time; also I want to exclude duplicates: only one ID.
>
> What can I do?
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org/
From | Date | Subject | |
---|---|---|---|
Next Message | Joshua D. Drake | 2006-10-26 17:32:55 | Re: NOTICE: word is too long INSERT 0 3014 |
Previous Message | Ottavio Campana | 2006-10-26 17:03:27 | more than 32 parameters to a function? |