Hi Mario,
you could try with https://moodle.org/plugins/tool_mergeusers: the issue here is that your duplication is based on using the same ID more than once while merging there means several accounts i.e. w/ different IDs which represent the same "logical" user.
The question is: what happened to your database?
Each user row should have a unique ID.
HTH,
Matteo