Write a SQL query to identify duplicate leads in a marketing database and return the most recent record for each lead at Pluralsight.
Treat nonblank email addresses as duplicates when they match after trimming whitespace and ignoring case. Exclude blank and NULL email addresses, and use lead_id as the tie-breaker when timestamps match.
lead_id, email, first_name, source, and created_atcreated_at descending and lead_id descending| Column | Type | Description |
|---|---|---|
| lead_idPK | INT | Unique identifier for the lead record |
| VARCHAR(255) | Email address supplied by the lead | |
| first_name | VARCHAR(100) | Lead first name |
| source | VARCHAR(100) | Marketing acquisition source |
| created_at | TIMESTAMP | Timestamp when the lead record was created |