pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Germán Gutiérrez <germangutierrezg@entelchile.net>
To: pgsql-sql@postgresql.org
Subject: Re: Delete duplicates
Date: Sun, 22 Jun 2003 14:33:06 -0400
Message-ID: <000a01c338ec$b9635d00$eaf1fea9@german> (raw)
In-Reply-To: <20030622091522.M37248@oasis.net.au>

Hi,

you need find duplicates and then you remove them

delete  from aap where id not in ( select max(id) from aap b where
aap.keyword = b.keyword );

Germán
Sorry about my english

-----Mensaje original-----
De: pgsql-sql-owner@postgresql.org
[mailto:pgsql-sql-owner@postgresql.org] En nombre de Rudi Starcevic
Enviado el: Domingo, 22 de Junio de 2003 5:15
Para: pgsql-sql@postgresql.org
Asunto: [SQL] Delete duplicates



Hi,

I have a table with duplicates and trouble with my SQL.
I'd like to keep a single record and remove older duplicates.
For example below of the 6 recods I'd like to keep records
4 and 6.

TABLE: aap
 id |     keyword
----+-----------------
  1 | LEAGUE PANTHERS
  2 | LEAGUE PANTHERS
  3 | LEAGUE PANTHERS
  4 | LEAGUE PANTHERS
  5 | LEAGUE BRONCOS
  6 | LEAGUE BRONCOS

Here is my SQL so far, it will select records 1 to 5 instead
of 1,2,3 and 5 only.

Any help greatly appreciated. I think I need a Group By somewhere in
there.

select a1.id
from aap a1
where id < ( SELECT max(id) FROM aap AS a2 )
AND EXISTS
(
SELECT *
FROM aap AS a2
WHERE a1.keyword = a2.keyword
)

Regards
Rudi.

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Attachments:

  smime.p7s (application/x-pkcs7-signature, 3.1K) download

view thread (10+ messages)  latest in thread

Message-ID: <000a01c338ec$b9635d00$eaf1fea9@german>
Permalink:  ../000a01c338ec$b9635d00$eaf1fea9@german/
Also on:    postgresql.org/message-id/000a01c338ec$b9635d00$eaf1fea9@german

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: germangutierrezg@entelchile.net
  Subject: Re: Delete duplicates
  In-Reply-To: <000a01c338ec$b9635d00$eaf1fea9@german>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox