Geeks With Blogs
Bunch's Blog One day I'll have a catchy subtitle, one day

Here is an easy way to find duplicate data in a table. This simple example would return any userNames that appear twice or more in the table.

SELECT userName, COUNT(userName) as UserDup
FROM tblUsers
GROUP BY userName
HAVING Count(userName) >= 2

I find this handy to use when users need to know how many times a certain item appears but there is no way to sort that data in their application or there is no report written for them to use. It is also a useful check when migrating data over from an older Access application that has been around for years to SQL Server. Frequently the Access application may not have checks for duplicates and over time (and many different users) several records for the same item may have been entered by mistake.

Technorati Tags:
Posted on Friday, November 6, 2009 1:25 AM | Back to top


Comments on this post: Finding Duplicates in a Table

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Bunch | Powered by: GeeksWithBlogs.net