On Wed, Nov 05, 2003 at 18:37:26 +0100,
Nabil Sayegh <postgresql@e-trolley.de> wrote:
> 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?
I don't think you are asking the right question. However, this ordering
will result in the correct record with a particular value for col_1
being used for the next step. This is all that is needed, since in the
next step the data will be sorted according to the original criteria.