Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Detect Duplicates in Database

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Detect Duplicates in Database. Start with the requirements and the two tables on the right.

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.

Problem

FanDuel needs a data-quality query to identify player records that may represent the same person. Records should be considered potential duplicates when they share a non-empty normalized email address or a normalized phone number.

Write a PostgreSQL query that returns each duplicate player pair and the source systems associated with both records.

Requirements

  1. Normalize emails by trimming whitespace and comparing them case-insensitively. Treat empty emails as missing.
  2. Normalize phone numbers by removing non-numeric characters. Treat missing phones as unavailable match keys.
  3. Return each unordered duplicate pair once, including the player IDs, names, matching reason, and source system names.
  4. Include players without a source-system row, and order results by the first and second player IDs.

Schema

players
ColumnTypeDescription
player_idPKINTEGERUnique player record identifier
full_nameVARCHAR(100)Player's full name
emailVARCHAR(255)Registered email address
phoneVARCHAR(30)Registered phone number, possibly formatted differently across sources
player_sources
ColumnTypeDescription
player_idINTEGERPlayer record identifier
source_nameVARCHAR(50)System that created or supplied the player record
Tablesplayersplayer_sources
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results