Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Remove Duplicate Leads in Meta Ads

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

Your question is Remove Duplicate Leads in Meta Ads. Start with the requirements and the two tables 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

Meta's business analytics team is reviewing lead data captured from Meta Lead Ads. Some leads were submitted multiple times for the same ad, and you need to identify those duplicate records and show how you would remove them while keeping one record per duplicate group.

Write a SQL query to find duplicate lead submissions, where a duplicate is defined as the same ad, email, and submission date. Keep the earliest lead_id as the canonical record.

Requirements

  1. Return only duplicate records from lead_submissions.
  2. For each duplicate group, show the campaign name from ad_campaigns.
  3. Mark which row should be kept and which rows should be removed using ROW_NUMBER().
  4. Order the output by campaign_name, submission_date, email, and lead_id.

Schema

lead_submissions
ColumnTypeDescription
lead_idPKINTUnique lead submission identifier
ad_idINTAd identifier associated with the lead
emailVARCHAR(255)Lead email address
full_nameVARCHAR(255)Lead full name
submission_dateDATEDate the lead was submitted
source_surfaceVARCHAR(100)Meta surface where the lead was captured
ad_campaigns
ColumnTypeDescription
ad_idPKINTUnique ad identifier
campaign_nameVARCHAR(255)Campaign name for the ad
objectiveVARCHAR(100)Campaign objective
Tableslead_submissionsad_campaigns
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results