Re: DISTINCT ... ORDER BY - Mailing list pgsql-novice

From Nabil Sayegh
Subject Re: DISTINCT ... ORDER BY
Date
Msg-id 3FA93556.20709@e-trolley.de
Whole thread Raw
In response to Re: DISTINCT ... ORDER BY  (Bruno Wolff III <bruno@wolff.to>)
Responses Re: DISTINCT ... ORDER BY  (Bruno Wolff III <bruno@wolff.to>)
List pgsql-novice
Bruno Wolff III wrote:

> I made a mistake in my example. In the distinct on subselect you have to
> order by the column(s) in the distinct on argument first. So in your example
> above the subselect should be:
> SELECT DISTINCT ON (col_1) col_1 FROM tab ORDER BY col_1, col_2='foo' DESC,
> col_1='bar' DESC, col_3='blah' DESC;

Hm, are you sure that this 'non-intended' ordering is reversible?

> In the outer select you use just the order by items that you want. Also
> note that the subselect will need to list all of the columns used in the
> order by in the outer select.



--
  e-Trolley Sayegh & John, Nabil Sayegh
  Tel.: 0700 etrolley /// 0700 38765539
  Fax.: +49 69 8299381-8
  PGP : http://www.e-trolley.de


pgsql-novice by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: DISTINCT ... ORDER BY
Next
From: Bruno Wolff III
Date:
Subject: Re: DISTINCT ... ORDER BY