Re: ORDER BY question

From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
To: "Christian Paul Cosinas" <cpc(at)cybees(dot)com>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: ORDER BY question
Date: 2006-05-11 03:55:19
Message-ID: E44B1B2B-C525-44E3-8FF0-1975D62A0FBB@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


On May 11, 2006, at 21:00 , Christian Paul Cosinas wrote:

> For example I have a table like this
>
> ID Name
> 1 A
> 1 B
> 2 C
> 2 D
>
> And I have a Query like this:
> SELECT * FROM table ORDER BY ID.
>
> Would my result always give me the same order or is there may be a
> possible
> different result?

It may give you a different result: if the order is not explicitly
specified by the ORDER BY clause, you are not guaranteed to get the
rows back in any particular order. So for cases where you may not be
ordering on a unique column (such as above), you may want to do
something like:

SELECT *
FROM table
ORDER BY "ID", "Name";

Hope this helps.

Michael Glaesemann
grzm seespotcode net

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Markus Schaber 2006-05-11 10:33:55 Re: Help with a seq scan on multi-million row table
Previous Message ogjunk-pgjedan 2006-05-11 03:47:11 Re: Help with a seq scan on multi-million row table