Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

How to delete duplicate entries from mysql table ?

user-image
Question added by Julfkar Moh Umar , Sr. Software Engineer , Aakash Edutech Private Limited
Date Posted: 2016/01/11
Mohammad Ahmad Siddiqui
by Mohammad Ahmad Siddiqui , Sr.Software Engineer , GSPANN

Hi,

Add primary key in your table then you can easily remove duplicate entry.

Example:-

DELETE FROM master_table  WHERE id IN (SELECT * FROM (SELECT id FROM master_table GROUP BY master_id, master_quiz, master_question, master_ans HAVING (COUNT(*) >1) ) AS A);

 

Hope this help.

 

 

Julfkar  Moh Umar
by Julfkar Moh Umar , Sr. Software Engineer , Aakash Edutech Private Limited

we insert auto increment on id column then run following command:

 

delete * from table_name where id > min(id) group by(column1,column2...collumnN) excluding column id

For example, with the following data:

SELECT*FROM names; +----+--------+| id | name |+----+--------+|1| google ||2| yahoo ||3| msn ||4| google ||5| google ||6| yahoo |+----+--------+

I would use SELECT DISTINCT name FROM names; if it were a SELECT query. How would I do this with DELETE to only remove duplicates and keep just one record of each?

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.