MySql Deletion of Row Data Where Count > 1

Hi,

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?

J
RidgejpManaging DirectorAsked:
Who is Participating?

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

x
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.

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

c
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.
0

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

J
0
Julian HansenCommented:
You are welcom
0
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.