Duplicate keys with conflicting values
Two rows share an identifier that should be unique, but disagree on other fields.
What it looks like
Before
| customer_id | city | updated | |
|---|---|---|---|
| C-104 | lena.park@example.com | Richmond | 2023-06-01 |
| C-104 | lena.park@example.com | Norfolk | 2024-02-10 |
| C-221 | omar.haddad@example.com | Durham | · |
| C-221 | o.haddad@example.com | Durham | · |
After
| customer_id | city | updated | |
|---|---|---|---|
| C-104 | lena.park@example.com | Norfolk | 2024-02-10 |
| C-221 | omar.haddad@example.com | Durham | · |
| C-221 | o.haddad@example.com | Durham | · |
How it happens
- A record was changed in one copy of the data and not in another, and the copies were later combined.
- An update was stored as a new row instead of replacing the old one.
- The same identifier was issued twice, so the rows describe two different things.
What it breaks
- Joins multiply rows, so every total downstream is inflated.
- Which value a report shows depends on row order, and can change from one run to the next.
- Loading into a table with a unique key either fails or silently keeps whichever row came last.
How to spot it
- Group by the key and count. Any key with more than one row is a candidate.
- Within each group, list the columns where values differ. One changed field suggests an update, many suggest two different entities.
- Check for a timestamp or version column that orders the rows.
How to fix it
- Work out whether the rows are versions of one record or two records sharing an identifier by mistake. The repairs are different.
- For versions, state the rule that picks the surviving value, such as the most recent update or the most trusted source, and apply it field by field.
- Where no rule settles a field, send it to a person instead of keeping whichever row happens to come first.
- Keep the rows that lost. They are the only record of what the conflict was.
- Exact duplicate rowsThe same row appears more than once, identical in every column.
- Near-duplicate recordsTwo rows describe the same real thing but differ enough that an exact comparison misses them.
- The same entity in two systemsOne person or organization exists in two systems under different identifiers, with nothing linking the records.
TermsPrimary key, Survivorship, Golden record, Source of truth