Skip site navigation (1) Skip section navigation (2)

Re: select distinct w/order by

From: Bob(dot)Henkel(at)hartfordlife(dot)com
To: Richard Huxton <dev(at)archonet(dot)com>
Cc: "John Liu" <johnl(at)emrx(dot)com>, pgsql-general(at)postgresql(dot)org,pgsql-general-owner(at)postgresql(dot)org
Subject: Re: select distinct w/order by
Date: 2004-03-31 20:52:00
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-general
Not that this is the issue, but what kind of tool where you using to get
your results back with this "other" database?  Sometimes these fancy GUI
tools like to be smart on you and order things based on something it feels
is correct giving you the impression that the database choose the order
when infact the GUI tool choose the order.  Just a thought

Bob Henkel          651-738-5085
Mutual Funds I/T Woodbury
Hartford Life
500 Bielenberg Drive
Woodbury, MN 55125

|         |           Richard Huxton         |
|         |           <dev(at)archonet(dot)com>     |
|         |           Sent by:               |
|         |           pgsql-general-owner(at)pos|
|         |             |
|         |                                  |
|         |                                  |
|         |           03/31/2004 02:37 PM    |
|         |                                  |
  |                                                                                                                              |
  |       To:       "John Liu" <johnl(at)emrx(dot)com>, <pgsql-general(at)postgresql(dot)org>                                                  |
  |       cc:                                                                                                                    |
  |       Subject:  Re: [GENERAL] select distinct w/order by                                                                     |

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,
> 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

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)

PRIVILEGED AND CONFIDENTIAL: This communication, including attachments, is for the exclusive use of addressee and may contain proprietary, confidential and/or privileged information.  If you are not the intended recipient, any use, copying, disclosure, dissemination or distribution is strictly prohibited.  If you are not the intended recipient, please notify the sender immediately by return e-mail, delete this communication and destroy all copies.

pgsql-general by date

Next:From: Mike MascariDate: 2004-03-31 20:53:22
Subject: Re: row-level security model
Previous:From: Richard HuxtonDate: 2004-03-31 20:37:19
Subject: Re: select distinct w/order by

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group