Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Find rows with duplicate entries
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01454248
Message ID:
01454251
Vues:
67
This message has been marked as the solution to the initial question of the thread.
>I am sure this question has been asked million times but here is a million one:
>
>What SQL Select to use to find all records with duplicate entries? I am trying to add a UNIQUE constraint to a table but get error that duplicate rows exist.
>
>TIA.

SQL Server 2005 and up
select * from (select *, 
count(*) over (partition by GroupField) as cntDups from myTable) X where cntDups > 1
SQL Server 2000 solution
select T.* from myTable T 
inner join (select GroupField, count(*) as cntDups from myTable group by GroupField having count(*) > 1) X
on T.GroupField = X.GroupField
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform