Re: (un)grouping question - Mailing list pgsql-general

From Jeff Davis
Subject Re: (un)grouping question
Date
Msg-id 1200941940.10057.503.camel@dogma.ljc.laika.com
Whole thread Raw
In response to (un)grouping question  ("Rhys Stewart" <rhys.stewart@gmail.com>)
Responses Re: (un)grouping question
List pgsql-general
On Mon, 2008-01-21 at 12:36 -0500, Rhys Stewart wrote:
> Hi list,
>
> have the following table
>
> uid|somevalue
> --------------------
> 1|11
> 2|44
> 3|31
> 4|44
> 5|71
> 6|33
> 7|33
> 8|44
> 9|14
>
> would like to remove the duplicate values in the column somevalue.
> doing this by just adding a random number  is perfectly fine, however
> i want to retain at least one of the original values of somevalue. Any
> ideas how to do this in in a query?

Would something like this help?

SELECT MIN(uid), somevalue FROM mytable GROUP BY somevalue;

Also consider just doing:

SELECT DISTINCT somevalue FROM mytable;

...if you don't need uid in the result set.

Regards,
    Jeff Davis


pgsql-general by date:

Previous
From: Reece Hart
Date:
Subject: Re: (un)grouping question
Next
From: Bob Pawley
Date:
Subject: Graphics