Write a query to identify duplicate records in a user streaming history table and keep only the most recent entry.
Assume records are duplicates when they share the same user_id, content_id, and started_at. The most recent entry is the one with the greatest ingested_at; use record_id as a final tie-breaker.
record_id, user_id, content_id, started_at, ingested_at, and device_type.user_id, content_id with nulls last, started_at, and newest ingested_at first.| Column | Type | Description |
|---|---|---|
| record_idPK | INT | Unique identifier for the ingested history record |
| user_id | INT | Identifier of the streaming user |
| content_id | VARCHAR(100) | Identifier of the streamed content |
| started_at | TIMESTAMP | Time when the streaming event began |
| ingested_at | TIMESTAMP | Time when the record was loaded into the history table |
| device_type | VARCHAR(30) | Device used for the streaming session |