Pregunta

MS Access database was corrupted and in one table few rows was duplicated. They are absolutely same and there isn't any unique field between duplicates, even primary keys. Because of this, primary key was reseted from this table after repairing database. Now I can only know rows that were duplicated:

select * from tablename
where id in(
select id from tablename
group by id
having count (*) > 1)

To designate primary key I must delete one of two duplicates, but don't know how.

¿Fue útil?

Solución

One way you can do this is with a temporary table:

select distinct t.*
into TempTABLE
from tablename t;

delete from tablename;

insert into tablename
    select *
    from TempTable;

That is, remove the duplicates using distinct. Delete all the rows from the original table, and then insert the unique rows.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top