Re: distinct

From: John McKown <joarmc(at)swbell(dot)net>
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:07:14
Message-ID: Pine.LNX.4.21.0010091903240.28048-100000@linux2.johnmckown.net
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.

The DISTINCT keyword means that the row returned (all values
considered together) is
DISTINCT. Not just that the first variable is DISTINCT. So a row having
values of 'a','b' and another row with 'a','c' are distinctly different in
that the second variable is not the same. I don't know of a way to say
that you want "col1" to be distinct. In the above case, which row should
be returned? I.e. if there are two different values for col2, which single
one is returned? random? lowest value?

I hope this makes sense, but I fear that I didn't do a good job of
explaining.

John

In response to

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

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2000-10-10 00:08:45 Re: Problem with NULL value in arguments of server-side functions ( plpgsql )
Previous Message Tim Kientzle 2000-10-10 00:06:37 Re: [GENERAL] Using BLOBs with PostgreSQL