Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Detect Duplicate Student Profiles
00:00
5 left

Detect Duplicate Student Profiles

HardSQL · PostgreSQL

Problem

Write a SQL query to identify duplicate student profiles across multiple legacy databases based on partial matching criteria.

Use the three legacy student tables. Treat two profiles as duplicates when at least two of these non-null criteria match: normalized email, normalized phone digits, date of birth, or a name key consisting of the first initial and normalized last name. Do not match profiles from the same source database.

Output

  1. One row per matching profile pair, with profile_id_a, source_a, profile_id_b, source_b, matching_criteria, and match_score.
  2. Include only pairs with at least two matching criteria.
  3. Sort by source_a, profile_id_a, source_b, and profile_id_b.

Schema

legacy_alpha_students
ColumnTypeDescription
legacy_idPKINTProfile identifier in the Alpha database
first_nameVARCHAR(100)Student first name
last_nameVARCHAR(100)Student last name
emailVARCHAR(255)Student email address
phoneVARCHAR(30)Student phone number
date_of_birthDATEStudent date of birth
legacy_beta_students
ColumnTypeDescription
legacy_idPKINTProfile identifier in the Beta database
first_nameVARCHAR(100)Student first name
last_nameVARCHAR(100)Student last name
emailVARCHAR(255)Student email address
phoneVARCHAR(30)Student phone number
date_of_birthDATEStudent date of birth
legacy_gamma_students
ColumnTypeDescription
legacy_idPKINTProfile identifier in the Gamma database
first_nameVARCHAR(100)Student first name
last_nameVARCHAR(100)Student last name
emailVARCHAR(255)Student email address
phoneVARCHAR(30)Student phone number
date_of_birthDATEStudent date of birth
Tableslegacy_alpha_studentslegacy_beta_studentslegacy_gamma_students
Interviewer

Your question is Detect Duplicate Student Profiles. Start with the requirements and the three 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.