MySql Deletion of Row Data Where Count > 1


Just to want an easy way to thin out duplication in a table. I have column1, column2 and column3 - where the count of column1 is greater than 1 then I need a select statement to perform a delete query that limits the deletion to 1.

Any thoughts?

Who is Participating?
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.

Why would you have duplicate content, could you elaborate...
Julian HansenCommented:
I usually do this in two steps

reate temporary table _temp (id, total);

insert into _temp (id, total) select max(id), count(*) from targetTable group by id;

delete from targetTable where id not in (select id from _temp);

Open in new window

It is possible to use sub queries as well - it all depends on where you want to run this from and how often.

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
RidgejpAuthor Commented:
Thanks Julian. Exactly what I needed.

Julian HansenCommented:
You are welcom
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
MySQL Server

From novice to tech pro — start learning today.