Delete Duplicate records in sql server [duplicated]

0

I have the following Query with which I get the number of times that is repeated every id_turner in my table rol_por_tercero .

use DatabaseName select id_tercero,COUNT(*)CantidadRepetidos from rol_por_tercero group by id_tercero having COUNT(*)>1

I want to delete a record of the ones that are repeated for each id and leave the other because they generate all the ids are repeated twice

The table in which these records exist is called role_by_third and the field is named id_rol_tiercero . Any ideas on how to do it?

    
asked by Andrex_11 26.01.2018 в 21:28
source

1 answer

1

Create a temporary table with the same structure as your main table. With a cursor, get all the ids, and do not appear repeated, you get it by typing:

SELECT DISTINCT id_tercero ...

Using SELECT TOP 1 and filtering through the ID, you rescue a record and store it in the temporary table. Once the loop is finished in the temporary table, you will have a record of each one of the cases without the need to repeat it.

    
answered by 29.01.2018 в 06:05