Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Remove Duplicate Customer Leads

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

Your question is Remove Duplicate Customer Leads. 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

Nimbus CRM stores inbound sales leads, but duplicate rows can appear because the source system does not provide a reliable unique business key. You need to identify duplicate lead records and determine which rows should be removed.

Write a SQL query to return the duplicate rows that should be deleted, keeping only the earliest created_at row within each duplicate group.

Requirements

  1. Treat rows as duplicates when full_name, email, phone, and source_channel are all the same.
  2. For each duplicate group, keep the earliest created_at row.
  3. Return only the rows that should be removed.
  4. Include the duplicate rank within each group and order the output by duplicate fields, then created_at.

Schema

customer_leads
ColumnTypeDescription
lead_row_idPKINTPhysical row identifier for each stored lead record
full_nameVARCHAR(100)Lead full name
emailVARCHAR(150)Lead email address
phoneVARCHAR(30)Lead phone number
source_channelVARCHAR(50)Channel where the lead originated
created_atTIMESTAMPTimestamp when the row was inserted
Tablescustomer_leads
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results