Re: DISTINCT ... ORDER BY

From: Nabil Sayegh <postgresql(at)e-trolley(dot)de>
To: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
Cc: pgsql-novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: DISTINCT ... ORDER BY
Date: 2003-11-05 17:03:35
Message-ID: 3FA92D67.4000200@e-trolley.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Stephan Szabo wrote:

>>should return:
>>
>>myDistinctOrderedCol
>>--------------------
>>a
>>c
>>b
>>
>>The problem is that DISTINCT complains about ORDER BY entries not being in the target list.
>
>
> Right, because given this data:
> col1 | col2
> a | b
> b | c
> b | a
>
> what ordering should
> select distinct col1 from tab order by col2
> give you?

I want it to just return 1 column ;)

> Does it put b first because there's a col2 with a, or b second because
> there's a col2 with b or is it indeterminate?

It shall not mention col2 at all.
The idea is to
1. ORDER BY expressions
2. Pick only 1 column
3. make this column distinct without losing the sort order

> Maybe something of this general form would work if you want to order by
> the minimums:
> select col3 from tablename group by col3 order by min(col1), min(col2),
> col3, min(col4);

Good idea.
But it would require me to introduce row numbers.
What now ?

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

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Bruno Wolff III 2003-11-05 17:12:25 Re: DISTINCT ... ORDER BY
Previous Message Nabil Sayegh 2003-11-05 16:52:03 Re: DISTINCT ... ORDER BY