Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

SQL Server :trova i duplicati in una tabella in base ai valori in una singola colonna

select
 employeename,
 IDs = STUFF((SELECT ','+ CAST(e2.[ID] AS VARCHAR(10)) 
  FROM emp e2
  WHERE e2.employeename = e1.employeename
  For XML PATH('')
 ),1,1,'')
FROM emp e1
GROUP BY employeename having COUNT(*) > 1

SQL Fiddler