Copying duplicate records to a seperate table

I have a table named Customers. I want to identify records in the Customer table
that have the same CustomerId. In otherwords I want to identify the duplicate records.
What I need to do, is to copy the duplicate records to a table named "Duplicates".
Can someone help me to write the query? Below is my Customers table with the duplicate
records. And below that is the Duplicates table, after it has been populated based upon
a query from the Customers table.


CustomerId   CustFullName      EntryDate           CustIsActive
233456700    Jim Carslon           2/10/2012              1
233456700    Jim Carlson           5/06/2013              1
544667890    Troy Salano          3/05/2011              1
111789999    Mary Dropsi         4/07/2014              1
111789999    Mary Dropsi         5/06/2009              1
111789999    Mary Dropsi          5/06/2013             1
566897004    Travis Goldman    7/10/2012             0
566897004    Travis Goldman    2/12/2015             0
666789000    Lori Mazelton       4/10/2008              1


233456700    Jim Carslon         2/10/2012              1
233456700    Jim Carlson         5/06/2013              1
111789999    Mary Dropsi        4/07/2014              1
111789999    Mary Dropsi        5/06/2009              1
111789999    Mary Dropsi        5/06/2013              1
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Walter RitzelSenior Software EngineerCommented:
In a rough mode, this is it.
insert into duplicates
select *
from customers
where CustomerId in (select CustomerId from customers group by CustomerId having count(1) > 1)

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
awking00Information Technology SpecialistCommented:
Given the records you show as duplicates, I think the above proposed solution just needs to add -
where CustIsActive = 1
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.