From: Mario Filipe <mjnf@uevora.pt>
To: Sferacarta Software <sferac@bo.nettuno.it>
Cc: pgsql-sql@postgresql.org
Subject: RE: Re[2]: [SQL] Query to eliminate duplicates
Date: Thu, 03 Dec 1998 15:07:50 -0000 (WET)
Message-ID: <XFMail.981203150750.mjnf@uevora.pt> (raw)
In-Reply-To: <2657.981203@bo.nettuno.it>
On 03-Dec-98 Sferacarta Software wrote:
> Hello Mario,
>
> giovedì, 3 dicembre 98, you wrote:
>
>
> MF> On 02-Dec-98 Sferacarta Software wrote:
>>> MF> Is there a way to eliminate duplicate records using just SQL?
>>>
>>> SELECT DISTINCT ...
>
> MF> I deserved that!
>
> MF> The problem is that i have a table where there are duplicate
> records
> MF> and i want to delete them! I tryed creating a unique index but it told me
> it
> MF> couldn't because it didn't have a function to do something (I think it is
> MF> because i had a boolean field in it)
>
>
> select * from TABELA where COLUNA in (
> select COLUNA from TABELA group by COLUNA having 1 < count(COLUNA)
> );
>
This would work (i believe you) but in my case i'm looking into a table
where there are at least 3 columns to look at!
It's a table where I keep the information about wich are the
disciplines where a student is enrolled:
Ex:
numero_aluno|codigo_disciplina|ano_lectivo|epoca|semestre
------------+-----------------+-----------+-----+--------
10335| 1207|1998/1999 | 1|f
10335| 1208|1998/1999 | 1|f
10335| 1209|1998/1999 | 1|f
10335| 1203|1998/1999 | 1|f
10335| 1205|1998/1999 | 1|f
10335| 1212|1998/1999 | 1|f
10335| 1213|1998/1999 | 1|f
10335| 1215|1998/1999 | 1|f
In this case there are no duplicates but in this one there are:
numero_aluno|codigo_disciplina|ano_lectivo|epoca|semestre
------------+-----------------+-----------+-----+--------
13427| 35|1998/1999 | 1|t
13427| 904|1998/1999 | 1|f
13427| 122|1998/1999 | 1|t
13427| 907|1998/1999 | 1|f
13427| 481|1998/1999 | 1|f
13427| 286|1998/1999 | 1|t
13427| 368|1998/1999 | 1|t
13427| 35|1998/1999 | 1|t
13427| 904|1998/1999 | 1|f
13427| 122|1998/1999 | 1|t
So a duplicate is actually a record that looks exactly like other record on the
table...
Thanks for your help anyway
Mario Filipe
mjnf@uevora.pt
http://neptuno.sc.uevora.pt/~mjnf
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: mjnf@uevora.pt, sferac@bo.nettuno.it
Subject: Re: [SQL] Query to eliminate duplicates
In-Reply-To: <XFMail.981203150750.mjnf@uevora.pt>
References: <2657.981203@bo.nettuno.it> <XFMail.981203150750.mjnf@uevora.pt>
* 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