Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Flag and Remove Duplicate Customers

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

Your question is Flag and Remove Duplicate Customers. Start with the requirements and the one table 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

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
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results