Re: How to remove duplicate lines but save one of the lines?

From: btober(at)ct(dot)metrocast(dot)net
To: A B <gentosaker(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to remove duplicate lines but save one of the lines?
Date: 2008-07-21 17:04:15
Message-ID: 4884C18F.4040203@ct.metrocast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

A B wrote:
> I have a table with rows like this
> A 1
> A 1
> B 3
> B 3
> C 44
> C 44
> and so on.
>
> and I want it to be
> A 1
> B 3
> C 44
>
> so how can I remove the all the duplicate lines but one?
>

CREATE TEMP TABLE tmp AS SELECT DISTINCT * FROM t1;
DROP TABLE t1;
CREATE TABLE t1 AS SELECT * FROM tmp;

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jack Orenstein 2008-07-21 20:05:01 COPY between 7.4.x and 8.3.x
Previous Message brian 2008-07-21 16:45:53 Re: Calling Python functions with parameters