I need to DELETE
duplicated rows for specified sid on a MySQL
table.
How can I do this with an SQL query?
DELETE (DUPLICATED TITLES) FROM table WHERE SID = "1"
Something like this, but I don't know how to do it.
I need to DELETE
duplicated rows for specified sid on a MySQL
table.
How can I do this with an SQL query?
DELETE (DUPLICATED TITLES) FROM table WHERE SID = "1"
Something like this, but I don't know how to do it.
This works for large tables:
To delete oldest change
max(id)
tomin(id)
There are just a few basic steps when removing duplicate data from your table:
Here is the full tutorial: https://blog.teamsql.io/deleting-duplicate-data-3541485b3473
This procedure will remove all duplicates (incl multiples) in a table, keeping the last duplicate. This is an extension of Retrieving last record in each group
Hope this is useful to someone.
This always seems to work for me:
Which keeps the lowest ID on each of the dupes and the rest of the non-dupe records.
I've also taken to doing the following so that the dupe issue no longer occurs after the removal:
In other words, I create a duplicate of the first table, add a unique index on the fields I don't want duplicates of, and then do an
Insert IGNORE
which has the advantage of not failing as a normalInsert
would the first time it tried to add a duplicate record based on the two fields and rather ignores any such records.Moving fwd it becomes impossible to create any duplicate records based on those two fields.