Write a SQL query to identify and remove duplicate records from a staging table without dropping the primary key constraints.
Treat rows with identical values in source_system, external_record_id, event_type, and payload as duplicates. Retain the row with the smallest staging_id for each duplicate set, and remove the other rows.
staging_id, source_system, external_record_id, event_type, and payload.staging_id ascending.| Column | Type | Description |
|---|---|---|
| staging_idPK | INTEGER | Unique identifier for the staged record |
| source_system | VARCHAR(40) | System that produced the incoming record |
| external_record_id | VARCHAR(40) | Identifier assigned by the source system |
| event_type | VARCHAR(30) | Type of robotics event |
| payload | TEXT | Raw staged event payload |