A client migration needs one row per real person. Clean email = LOWER(TRIM(email)), treated as missing when NULL or blank. Clean phone = the digits of phone only (drop spaces, '+', '-', '(', ')', '.'), keeping the LAST 10 digits; missing when no digits. Identity key: the clean email if present; otherwise the clean phone; otherwise the contact is unique on its own. Within each identity keep the row with the latest updated_at (tie: larger contact_id). Return contact_id, full_name (TRIM), clean_email and clean_phone (NULL when missing). Order by contact_id.
| Column | Type |
|---|---|
| contact_id | INTEGER |
| full_name | TEXT |
| TEXT | |
| phone | TEXT |
| updated_at | TIMESTAMP |
| contact_id | full_name | phone | updated_at | |
|---|---|---|---|---|
| 1 | Rohit Sharma | Rohit.S@Mail.com | +91 98290-11111 | 2026-01-10 10:00:00 |
| 2 | Rohit S | rohit.s@mail.com | 9829011111 | 2026-02-01 09:00:00 |
| 3 | Neha Gupta | NULL | (982) 902-2222 | 2026-01-05 08:00:00 |
| 4 | Neha G. | +91-9829022222 | 2026-01-20 08:00:00 | |
| 5 | Arjun Rao | arjun@corp.in | 9829033333 | 2026-01-15 12:00:00 |
| 6 | Meena Iyer | NULL | NULL | 2026-01-01 00:00:00 |
| contact_id | full_name | clean_email | clean_phone |
|---|---|---|---|
| 2 | Rohit S | rohit.s@mail.com | 9829011111 |
| 4 | Neha G. | NULL | 9829022222 |
| 5 | Arjun Rao | arjun@corp.in | 9829033333 |
| 6 | Meena Iyer | NULL | NULL |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ Parse Error Logs by Module · Normalise Messy Expense Claims ›
{{ totalCount }} questions in the style asked at Amazon, Microsoft, Google, Meta, Flipkart and more — {{ hardPct }}% Hard. Write SQL in a real database engine in your browser, run it on sample data, then evaluate against hidden tests.
Company tags show where this type of question is commonly reported in interviews. Questions, data and solutions are written by TechTown.
{{ cur.statement }}
No submissions yet. Press Evaluate to submit your query.
{{ solutionSql }}
{{ out.error }}
You have solved your 3 free questions — nice work! Log in (free) to unlock all 150 questions, keep your streak and appear on the leaderboard.