Write a query to remove duplicate rows from a table while keeping the latest record.
Use records and treat rows with the same customer_id and event_type as duplicates. The latest row is determined by recorded_at, with record_id as the tie-breaker when timestamps match.
record_id, customer_id, and event_type values.| Column | Type | Description |
|---|---|---|
| record_idPK | INT | Unique record identifier |
| customer_id | INT | Customer associated with the event |
| event_type | VARCHAR(30) | Type of customer event |
| payload | TEXT | Event data stored with the record |
| recorded_at | TIMESTAMPTZ | Time when the event was recorded |