Hello readers!. If you having the much of redundant/duplicate data growing in your database you can delete it with just a single query as I wrote here.
Let say I have a table Address and want to delete the all the duplicate records whose city column is same
or we can delete any records sharing same column type.
DELETE e1 FROM Address e1, Address e2 WHERE e1.id > e2.id AND e1.city = e2.city
After this query all your duplicate records which comes later will be deleted. And if you want to keep the latest one records you just need to reverse the '>' with '<' and new query will go like this
DELETE e1 FROM Address e1, Address d2 WHERE e1.id < e.id AND e1.city = e2.city
0 Comment(s)