Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
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
Deduplicate Policy Records
00:00
5 left

Deduplicate Policy Records

MediumSQL · PostgreSQL

Problem

Write a SQL query to identify duplicate policy records within a database and retain only the most recently updated entry.

Treat records with the same policy_number as duplicates. If update timestamps are tied, retain the record with the greatest policy_id. Do not include older duplicate records.

Output

  1. One row per retained policy number, with columns policy_id, policy_number, policyholder_name, policy_status, premium_amount, and updated_at.
  2. Include the most recently updated record for every policy number, including policy numbers without duplicates.
  3. Order by policy_number ascending.

Schema

policies
ColumnTypeDescription
policy_idPKINTEGERUnique identifier for a policy record version
policy_numberVARCHAR(30)Business identifier used to detect duplicate policy records
policyholder_nameVARCHAR(100)Name of the policyholder
policy_statusVARCHAR(20)Current status recorded for the policy version
premium_amountNUMERIC(12,2)Policy premium amount
updated_atTIMESTAMPTimestamp when the policy record was last updated
Tablespolicies
Interviewer

Your question is Deduplicate Policy Records. Start with the requirements and the one table 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.