VPS business hosting starting at $29.95/24/7 premium technical support

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)

Author: Harshvardhan Malpani

PHP Developer based in New Delhi, India. Working as a freelance web developer providing server deployment, website development and maintenance services.

Leave a Reply

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