Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
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.

Output details

  • Sort source_a, profile_id_a, source_b, and profile_id_b ascending.
  • Orient each pair with the lexicographically smaller source in source_a, emitting each cross-source pair once.
  • Normalize email by trimming, lowercasing, removing whitespace, and treating an empty result as NULL; normalize phone by retaining digits and treating empty as NULL.
  • Construct name_key from the lowercased first alphanumeric character of first_name and lowercased alphanumeric last_name, treating an empty result as NULL.
  • List matching_criteria in the order email, phone, date_of_birth, name_key, separated by , with no trailing separator.

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
Sign up free to run your codeLog inLn 1
Run your query to see results here.