Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

How to delete duplicate entries from mysql table ?

user-image
Question ajoutée par Julfkar Moh Umar , Sr. Software Engineer , Aakash Edutech Private Limited
Date de publication: 2016/01/11
Mohammad Ahmad Siddiqui
par 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
par 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

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?