Skip to content

Instantly share code, notes, and snippets.

@Guley
Last active December 4, 2023 07:38
Show Gist options
  • Save Guley/86422d60e1fe3be33c2c548c24f58d5e to your computer and use it in GitHub Desktop.
Save Guley/86422d60e1fe3be33c2c548c24f58d5e to your computer and use it in GitHub Desktop.
Remove duplicate entries from database a keep only one using MySql
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