Re: distinct - Mailing list pgsql-general

From Stephan Szabo
Subject Re: distinct
Date
Msg-id Pine.BSF.4.10.10010091657440.23140-100000@megazone23.bigpanda.com
Whole thread Raw
In response to distinct  ("Otwell, Andrew (ISSAtlanta)" <AOtwell@iss.net>)
Responses Re: distinct  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
On Tue, 3 Oct 2000, Otwell, Andrew (ISSAtlanta) wrote:

> I have attempted to run
> select distinct col1 from tablename;
> and it runs fine.
>
> When I run it in a real world environment:
> select distinct col1, col2, col3, col4 from tablename order by col1 desc,
> col2;
> It returns all the values from col1 which appears to be the same thing as
> not using distinct at all.
>
> Am I missing something? I'd like only distinct values on col1 and then I'll
> sort, include, or exclude the other columns.

That syntax above says get distinct values for all of col1, col2, col3,
col4, so (1,2,3,4) and (1,2,3,5) are not distinct and would both be
output.

There really isn't a spec way to do it, however,
 select distinct on (col1) col1, col2, col3, col4 from tablename;
would get you one row for each distinct col1, but it's undefined what
row that gets you.


pgsql-general by date:

Previous
From: "Amy Antle"
Date:
Subject: Question
Next
From: "Jono"
Date:
Subject: Oracle to POSTGRESQL