Re: DISTINCT ... ORDER BY

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Nabil Sayegh <postgresql(at)e-trolley(dot)de>
Cc: pgsql-novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: DISTINCT ... ORDER BY
Date: 2003-11-05 17:53:27
Message-ID: 20031105175327.GA6933@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Wed, Nov 05, 2003 at 18:37:26 +0100,
Nabil Sayegh <postgresql(at)e-trolley(dot)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.

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Stephan Szabo 2003-11-05 18:06:17 Re: DISTINCT ... ORDER BY
Previous Message Nabil Sayegh 2003-11-05 17:37:26 Re: DISTINCT ... ORDER BY