Re: Duplicate records

From: "Bart Degryse" <Bart(dot)Degryse(at)indicator(dot)be>
To: "Ezequias Rodrigues da Rocha" <ezequias(dot)rocha(at)gmail(dot)com>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Duplicate records
Date: 2007-02-02 14:13:11
Message-ID: 45C35506.A3DD.0030.0@indicator.be
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

The only table in my query is "mytable".
The part (select field1, field2, count(*) from mytable group by field1,
field2 having count(*) > 1)
counts how many records have the same field1 and field2 and returns a
record per combination of field1 and field2 that have more than one (=
duplicates)

The rest uses that information to filter all fields of all the records
from that same table having such a combination of field1 and field2
This version is even a little shorter:
select *
from mytable A, (select field1, field2 from mytable group by field1,
field2 having count(*) > 1) B
where A.field1 = B.field1 and A.field2 = B.field2

>>> "Ezequias Rodrigues da Rocha" <ezequias(dot)rocha(at)gmail(dot)com> 2007-02-02
14:59 >>>
Thank you but are you talking of two tables ? I intent to check in only
one table.

Please explain to me.

Ezequias

2007/2/2, Bart Degryse < Bart(dot)Degryse(at)indicator(dot)be>:

select *
from mytable A, (select field1, field2, count(*) from mytable group by
field1, field2 having count(*) > 1) B
where A.field1 = B.field1 and A.field2 = B.field2

>>> "Ezequias Rodrigues da Rocha" <ezequias(dot)rocha(at)gmail(dot)com (
mailto:ezequias(dot)rocha(at)gmail(dot)com )> 2007-02-02 14:48 >>>

Hi list,

I am making some data minning and would like to know if someone tell me
how to retrieve the duplicate records based in one or two fields of my
table.

Any help would be welcomed.

--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Atenciosamente (Sincerely)
Ezequias Rodrigues da Rocha
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

A pior das democracias ainda é melhor do que a melhor das ditaduras
The worst of democracies is still better than the better of
dictatorships
http://ezequiasrocha.blogspot.com/

--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Atenciosamente (Sincerely)
Ezequias Rodrigues da Rocha
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
A pior das democracias ainda é melhor do que a melhor das ditaduras
The worst of democracies is still better than the better of
dictatorships
http://ezequiasrocha.blogspot.com/

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Hiltibidal, Robert 2007-02-02 14:56:36 Re: Insert into a date field
Previous Message Shoaib Mir 2007-02-02 14:03:08 Re: Duplicate records