Re: Select distinct and order by. - Mailing list pgsql-sql

From Tod McQuillin
Subject Re: Select distinct and order by.
Date
Msg-id Pine.GSO.4.33.0107170818360.13580-100000@sysadmin
Whole thread Raw
In response to Select distinct and order by.  (Carlos <carlos@solaria-mediterranea.com>)
List pgsql-sql
On Wed, 11 Jul 2001, Carlos wrote:

> Select distinct field1, field2 from table1 order by field3;
>
> The value return by PQresultErrorMessage is:
>
> For SELECT DISTINCT, ORDER BY expressions must appear in target list

That's because this query is ambiguous.

What if table1 looks like this:

field1    field2    field3
------    ------    ------
a    b    1
a    b    3
c    d    2

What should your query return then?  Both

a    b
c    d

and

c    d
a    b

are valid, depending on which 'a b' row was chosen.

If 6.5.3 allowed that, it was a mistake to rely on it because the answer
is undefined.
-- 
Tod McQuillin



pgsql-sql by date:

Previous
From: Raymond Chui
Date:
Subject: Why lost all foreign key constraits after cluster?
Next
From: "Chris Ruprecht"
Date:
Subject: First steps in plpgsql - language not recognized?