Last active
December 4, 2023 07:38
-
-
Save Guley/86422d60e1fe3be33c2c548c24f58d5e to your computer and use it in GitHub Desktop.
Remove duplicate entries from database a keep only one using MySql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
delete table | |
from table | |
inner join ( | |
select max(id) as lastId, product_id | |
from table | |
group by product_id | |
having count(*) > 1) duplic on duplic.product_id = table.product_id | |
where table.id < duplic.lastId; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment