In SQL, how would you write a query to find duplicate records and keep only the latest row per group?
Use property_id as the duplicate grouping key. A group qualifies only when it contains more than one record. Return the latest record by updated_at, using the greatest record_id as the tie-breaker.
duplicate_countrecord_id, property_id, listing_status, price, updated_at, source_system, duplicate_countproperty_id ascending| Column | Type | Description |
|---|---|---|
| record_idPK | INT | Unique identifier for the ingested listing record |
| property_id | INT | Identifier used to group records for the same property |
| listing_status | VARCHAR(30) | Current status reported for the listing |
| price | DECIMAL(12,2) | Listing price at ingestion time |
| updated_at | TIMESTAMP | Timestamp when the source listing was last updated |
| source_system | VARCHAR(40) | System that supplied the record |