Identifying repeated data.
WHY IT ARISES
An import run twice A form submitting twice A plugin creating records repeatedly A migration that partly repeated
FINDING THEM
SELECT column, COUNT(*) as c FROM table GROUP BY column HAVING c > 1;
That lists values appearing more than once.
HAVING filters on the aggregate, where WHERE filters on individual rows. That distinction is why HAVING exists.
LOOKING AT THEM
Once you know which values repeat, select the full rows for one of them and examine what differs.
Frequently one is complete and the other is partial.
REMOVING THEM
Carefully. Decide which copy to keep, usually the oldest or the most complete.
Back up first.
Deleting duplicates while keeping one requires care: a naive DELETE removes all copies including the one you wanted.
THE SAFER ROUTE
Identify the specific ids to delete with a SELECT, check them, then delete by id.
Slower and considerably safer than a clever single query.