Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Duplicate Records

Author  Topic 

rcr69er
Constraint Violating Yak Guru

327 Posts

Posted - 2007-11-13 : 14:44:24
HI

I've just imported data into a table, I have found there are a number of duplicate records in the table.

Is there anyway to find all the duplicate records?

Thanks

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2007-11-13 : 14:48:52
select col1, col2
group by col1,col2
having count(*)>1

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-11-13 : 14:49:05
You can use GROUP BY with HAVING COUNT(*) > 1

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-11-13 : 14:49:45
Yes.
DELETE	f
FROM (
SELECT ROW_NUMBER() OVER (PARTITION BY ColA,ColB ORDER BY Col1, Col2) AS RecID
) AS f
WHERE RecID > 1



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2007-11-13 : 14:55:19
since this is the 2k5 forum, I bow to Peso's answer.

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page
   

- Advertisement -