Re: SELECT DISTINCT ON and ORDER BY

From: Volkan YAZICI <yazicivo(at)ttmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: SELECT DISTINCT ON and ORDER BY
Date: 2008-03-28 13:30:32
Message-ID: 87fxub562v.fsf@alamut.mobiliz.com.tr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, 28 Mar 2008, Sam Mason <sam(at)samason(dot)me(dot)uk> writes:
> On Fri, Mar 28, 2008 at 01:12:49PM +0100, Stanislav Raskin wrote:
>> The result in this case should be:
>>
>> id value order_field
>> 3 10 1
>> 5 12 2
>> 4 5 8

Yet another lame solution:

test=# SELECT max(id) AS id, min(value) AS value, min(weight) AS weight
FROM tmp
GROUP BY value
ORDER BY min(weight);
id | value | weight
----+-------+--------
3 | 10 | 1
5 | 12 | 2
4 | 5 | 8
(3 rows)

Regards.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adam Rich 2008-03-28 13:31:02 Re: Need help on how to backup a table
Previous Message Richard Huxton 2008-03-28 13:21:05 Re: Delete after trigger fixing the key of row numbers