1
I have several fields in my table but I have 4 that are being repeated and I cannot allow registration with these equal fields: COD
, TIPO_ATIVIDADE
, DT_VENCIMENTO
, `EXTRA_URGENTE_COMUM.
I have tried 4 different codes, even with the help of the old questions here of the forum and yet, whenever I run the query, it is running forever, does not give error or success, just runs and never leaves the "loop".
Codes I tried:
DELETE b FROM tbl_atividades a
INNER JOIN tbl_atividades b ON a.cod = b.cod AND a.tipo_atividade=b.tipo_atividade AND a.dt_vencimento=b.dt_vencimento AND b.codigo < a.codigo
DELETE t1 FROM tbl_atividades t1, tbl_atividades t2 WHERE t1.codigo > t2.codigo AND t1.cod = t2.cod AND t1.tipo_atividade = t2.tipo_atividade AND t1.dt_vencimento = t2.dt_vencimento AND t1.extra_urgente_comum = 'C'
DELETE FROM tbl_atividades
USING tbl_atividades, tbl_atividades AS auxtable
WHERE (NOT tbl_atividades.codigo = auxtable.codigo)
AND (tbl_atividades.cod = auxtable.cod)
AND (tbl_atividades.tipo_atividade = auxtable.tipo_atividade)
AND (tbl_atividades.dt_vencimento = auxtable.dt_vencimento)
AND (tbl_atividades.extra_urgente_comum = 'C')
How could I accomplish this deletion of duplicates otherwise?
Is this table very large? It has indexes?
– bfavaretto
Yes, it is large, but the number of duplicates is not so much. It has 135606 records, and duplicates contain around 500 only.
– Denied