Re: removing duplicates - sql

From: Tommi Maekitalo <t(dot)maekitalo(at)epgmbh(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: removing duplicates - sql
Date: 2002-08-22 06:13:08
Message-ID: 200208220813.08337.t.maekitalo@epgmbh.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Am Donnerstag, 22. August 2002 01:52 schrieb Johnson, Shaunn:
> Howdy:
>
> I have a table that has a primary key on it. Somewhere in
> the table, it seems to have a few duplicate records in it.
> I'm trying to weed out the duplicates, but am having problems
> with the sql.
>
...

Hi,

select distinct t1.name, t1.addr1, t1.phone, t1.city
from emp_table t1
where (select count(*) from emp_table t2
where t1.name = t2.name
and t1.addr1 = t2.addr1
and t1.phone = t2.phone
and t1.city = t2.city) > 1

will do it.

Tommi

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tommi Maekitalo 2002-08-22 06:21:10 Re: Mysql -> PgSQL
Previous Message Oliver Elphick 2002-08-22 06:10:27 Re: [ADMIN] How to execute my trigger when update certain columns