Remove new duplicates from any sql table

DELETE FROM yourTable 
WHERE id NOT IN (SELECT MIN(id) 
                 FROM yourTable 
                 GROUP BY anotherColumn)

If you want to remove older rows, use the following:

DELETE FROM yourTable 
WHERE id NOT IN (SELECT MAX(id) 
                 FROM yourTable 
                 GROUP BY anotherColumn)

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *