| From: | "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com> |
|---|---|
| To: | "Rhys Stewart" <rhys(dot)stewart(at)gmail(dot)com> |
| Cc: | pgsql-general(at)postgresql(dot)org |
| Subject: | Re: (un)grouping question |
| Date: | 2008-01-21 19:45:10 |
| Message-ID: | dcc563d10801211145l7676e59ftc4fe1959e5138d44@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
On Jan 21, 2008 11:36 AM, Rhys Stewart <rhys(dot)stewart(at)gmail(dot)com> 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?
I can get you halfway there. You want a query something like this to
identify all but one of the values:
select a.uid from sometable a left join sometable b on
(a.somevale=b.somevalue and a.uid > b.uid)
From there, you'll have to figure out the update part of problem. :)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Scott Marlowe | 2008-01-21 19:45:54 | Re: (un)grouping question |
| Previous Message | Colin Wetherbee | 2008-01-21 19:43:42 | Re: Problem of capital case-insensitive letter with accent |