Write a query to identify duplicate records in a table and safely delete them while keeping only the earliest entry.
Treat rows as duplicates when they share the same source_system, part_number, quantity, and event_time. The earliest entry is the one with the smallest loaded_at; use the smallest record_id as a deterministic tie-breaker. Handle nullable duplicate-key columns correctly.
record_id, source_system, part_number, quantity, event_time, and loaded_at.record_id ascending.| Column | Type | Description |
|---|---|---|
| record_idPK | INT | Unique record identifier |
| source_system | VARCHAR(50) | System that produced the record |
| part_number | VARCHAR(40) | Part or item identifier |
| quantity | INT | Recorded quantity |
| event_time | TIMESTAMP | Time associated with the source event |
| loaded_at | TIMESTAMP | Time the record was loaded |