Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to delete duplicate rows in a table set MySql

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.16k
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: