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

From Nabil Sayegh
Subject DISTINCT ... ORDER BY
Date
Msg-id 3FA848D4.3070202@e-trolley.de
Whole thread Raw
Responses Re: DISTINCT ... ORDER BY
Re: DISTINCT ... ORDER BY
List pgsql-novice
Hi all,

I have built a query that mainly orders all columns.
It shouldn't matter how it orders but FYI:
I need to order by 1 given column and then by all others from 'left to right'.

No problem so far.

Then I want to return only 1 column (e.g. the 3rd) with duplicates removed
_AND_ still in the same order like above.

e.g.:

myCol
-----
a
a
c
b
b
c
b

should return:

myDistinctOrderedCol
--------------------
a
c
b

The problem is that DISTINCT complains about ORDER BY entries not being in the target list.
Any idea ?

Example:

initial query:
SELECT * FROM tab ORDER BY col_2='foo' DESC, col_1='bar' DESC, col_3='blah' DESC;

Then something like:
SELECT DISTINCT col3 FROM {initial query};

TIA
--
  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: Josh Berkus
Date:
Subject: Re: Surrogate vs natural keys (Was: Almost relational PostgreSQL (was: one-to-one))
Next
From: Bruno Wolff III
Date:
Subject: Re: DISTINCT ... ORDER BY