Re: select distinct w/order by - Mailing list pgsql-general

From Richard Huxton
Subject Re: select distinct w/order by
Date
Msg-id 200403312137.19552.dev@archonet.com
Whole thread Raw
In response to select distinct w/order by  ("John Liu" <johnl@emrx.com>)
Responses Re: select distinct w/order by
List pgsql-general
On Wednesday 31 March 2004 18:50, John Liu wrote:
> I know this is an old topic, but it's not easy to find a way around it, so
> when we migrate SQL from other database to PostgreSQL, it causes a huge
> headache. Here's an extremely simple example -
>
> The original simple SQL -
> select distinct atcode from TMP order by torder;

Can you explain what this means? If I have

atcode | torder
AAA    | 20
BBB    |  5
CCC    | 10
BBB    | 45
CCC    | 27

What order should we get?
You could argue for:
1. BBB,CCC,AAA since that is the order of the min(torder)
2. AAA,CCC,BBB since that is the order of the max(torder)
3. AAA,BBB,CCC if you take the first(torder) you find reading down the page
4. AAA,CCC,BBB if you take the first(torder) but read up the page

Which one should PG pick, and how should it know?

Which one did the other database pick, and why was it right to do so?

--
  Richard Huxton
  Archonet Ltd

pgsql-general by date:

Previous
From: "Dann Corbit"
Date:
Subject: Re: Wich hardware suits best for large full-text indexed databases
Next
From: "Marc G. Fournier"
Date:
Subject: Re: [pgsql-advocacy] Best open source db poll currently