Re: ORDER BY question - Mailing list pgsql-sql

From Michael Glaesemann
Subject Re: ORDER BY question
Date
Msg-id E44B1B2B-C525-44E3-8FF0-1975D62A0FBB@seespotcode.net
Whole thread Raw
In response to ORDER BY question  ("Christian Paul Cosinas" <cpc@cybees.com>)
List 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





pgsql-sql by date:

Previous
From: "Christian Paul Cosinas"
Date:
Subject: ORDER BY question
Next
From: Markus Schaber
Date:
Subject: Re: Help with a seq scan on multi-million row table