Write a query to find and delete duplicate records from a database table while retaining the original entry.
Use the customer_contacts table. Treat records as duplicates when they have the same customer_id, case-insensitive trimmed email, phone number, and source_system. Retain the record with the earliest created_at; use the lowest id as the tie-breaker.
id, customer_id, email, phone, source_system, and created_at.| Column | Type | Description |
|---|---|---|
| idPK | INT | Unique contact record identifier |
| customer_id | INT | Identifier of the customer associated with the contact |
| VARCHAR(255) | Customer email address | |
| phone | VARCHAR(30) | Customer phone number |
| source_system | VARCHAR(50) | System that created or imported the record |
| created_at | TIMESTAMP | Timestamp when the record was created |