Re: distinct

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: "Otwell, Andrew (ISSAtlanta)" <AOtwell(at)iss(dot)net>
Cc: "'pgsql-general(at)postgresql(dot)org'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: distinct
Date: 2000-10-10 00:03:31
Message-ID: Pine.BSF.4.10.10010091657440.23140-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

  • distinct at 2000-10-03 20:35:36 from Otwell, Andrew (ISSAtlanta)

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tim Kientzle 2000-10-10 00:06:37 Re: [GENERAL] Using BLOBs with PostgreSQL
Previous Message Raymond O'Donnell 2000-10-09 22:44:27 ADO transaction funny