-1

I am trying to use the following code to remove duplicate entries from a column called herit. The name of my table is people

DELETE FROM people
 WHERE herit NOT IN (SELECT * 
                    FROM (SELECT MIN(n.herit)
                            FROM people n
                        GROUP BY n.herit) x)

Although this code is executed and it states "5 rows affected", it doesn't remove duplicates from my table in mysql.

What could possibly be wrong? I searched all over the internet, couldn't find anything satisfactory

Prasinus Albus
  • 406
  • 1
  • 3
  • 21

1 Answers1

1

Try this one..

DELETE FROM people WHERE id NOT IN 
(SELECT id FROM (SELECT id FROM people GROUP BY herit HAVING count(herit) > 1 
OR count(herit) = 1) newTable)

enter image description here

This is actual and resultant table

Sumit
  • 1,702
  • 2
  • 14
  • 20