Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Duplicate Records and Data Quality
00:00
5 left

Duplicate Records and Data Quality

MediumSQL · PostgreSQL

Problem

How do you handle duplicate records and ensure data quality before performing your analysis?

Use raw_records and record_sources to identify duplicate external record keys. Retain one quality-valid record per duplicate group, prioritizing valid data, then the most recently updated record.

Output

  1. One row per duplicate group with external_record_key, canonical_record_id, duplicate_count, and quality_issue_count
  2. Exclude groups with no quality-valid record
  3. Sort by external_record_key ascending

Schema

record_sources
ColumnTypeDescription
source_idPKINTUnique source identifier
source_nameVARCHAR(100)Name of the originating source
is_activeBOOLEANWhether the source is currently trusted
raw_records
ColumnTypeDescription
record_idPKINTUnique raw record identifier
external_record_keyVARCHAR(50)Business key used to identify duplicate records
source_idINTOriginating source identifier
customer_emailVARCHAR(255)Customer email address
event_dateDATEDate associated with the record
amountDECIMAL(10,2)Recorded amount
updated_atTIMESTAMPTimestamp of the latest source update
Tablesraw_recordsrecord_sources
Interviewer

Your question is Duplicate Records and Data Quality. Start with the requirements and the two tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.