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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
Flag and Remove Duplicate Customers
00:00
5 left

Flag and Remove Duplicate Customers

MediumSQL · PostgreSQL

Problem

NovaCart stores customer signups in a raw intake table and sometimes receives duplicate records for the same person. Write a SQL query to identify duplicates and mark which rows should be kept versus flagged for review.

Requirements

  1. Treat records as duplicates when they have the same email_address and signup_date.
  2. Keep the row with the earliest created_at; if there is a tie, keep the smallest customer_id.
  3. Return only duplicate groups, including both the kept row and the rows that should be flagged.
  4. Output the duplicate group key, row rank within the group, and a record_status column with values keep or flag_duplicate.

Schema

customer_signups
ColumnTypeDescription
customer_idPKINTUnique row identifier for each signup record
full_nameVARCHAR(100)Customer name from the source system
email_addressVARCHAR(255)Customer email used to detect duplicates
signup_dateDATEBusiness signup date used in duplicate matching
source_systemVARCHAR(50)Source that created the signup record
created_atTIMESTAMPInsertion timestamp used to decide which duplicate to keep
is_activeBOOLEANWhether the signup is currently active
Tablescustomer_signups
Interviewer

Your question is Flag and Remove Duplicate Customers. 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.