[wd_asp elements=’search’ ratio=’100%’ id=1]

Find Duplicates – delete duplicate and keep higher/lower one

18th October 2013

MySql

mysql codehaven category

SELECT COUNT(*) as repetitions, campaign,client
FROM cmdata
GROUP BY client,campaign
HAVING repetitions > 1

This SQL will delete any duplicates in campaignid, and keeps the higher id one

DELETE u1 FROM targets u1, targets u2 WHERE u1.id < u2.id AND u1.campaignid = u2.campaignid