Deduplicate Patient Records Across Pharmacy and Aetna Claims Feeds
Last updated: November 29, 2026
Quick Overview
Pharmacy patient profiles and Aetna member records arrive in one staging table with source, first_name, last_name, dob, zip, phone and updated_at. Write SQL that groups likely duplicates by normalized name, date of birth and zip, and keeps one golden record per person, preferring the most recently updated row with a phone number.
CVS Health
November 29, 20260
0
0 solved
Pharmacy patient profiles and Aetna member records arrive in one staging table with source, first_name, last_name, dob, zip, phone and updated_at. Write SQL that groups likely duplicates by normalized name, date of birth and zip, and keeps one golden record per person, preferring the most recently updated row with a phone number.
After the Aetna acquisition, CVS Health links retail pharmacy, MinuteClinic and insurance data for the same person, and identity resolution is a recurring data engineering problem. The interviewer looks for normalization before matching and a deterministic survivorship rule.
What the Interviewer Expects
- Normalizes names (trim, lowercase, strip punctuation) before matching
- Uses ROW_NUMBER with an explicit survivorship ORDER BY
- Keeps a mapping from every source id to the golden id
- Discusses false merges versus missed matches
- Mentions that PHI matching rules need governance review
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you handle twins who share last name, DOB and zip?
- How would you add fuzzy matching on names like Jon versus John?
- How do you keep golden ids stable when new records arrive daily?
- What metrics tell you the matching is getting worse?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
staging_people(source, source_id, first_name, last_name, dob, zip, phone, updated_at). Sources are rx and aetna. Names have case and spacing noise, zips may be ZIP+4. A blocking key of normalize...
Approach
- Normalize fields in a CTE.
- Build
match_keyfrom normalized fields. - Rank rows within each key: rows with a phone first, then most recent
updated_at, then a stable tiebreaker. - Rank 1 is ...