Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Deduplicate Meta Lead Form Submissions

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

Your question is Deduplicate Meta Lead Form Submissions. Start with the requirements and the three 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 lead ingestion pipeline for Facebook Lead Ads occasionally creates duplicate submission records for the same lead and form. Write a SQL query to identify the canonical record to keep for each duplicated lead and return only the duplicate rows that should be removed.

Requirements

  1. Treat records as duplicates when they share the same lead_id and form_id.
  2. Preserve the earliest valid submission by ranking rows using submitted_at ascending, then ingested_at ascending, then submission_id ascending.
  3. Return only rows that should be deleted, along with campaign and advertiser context.
  4. Exclude rows tied to inactive campaigns so cleanup only applies to active data.

Schema

lead_submissions
ColumnTypeDescription
submission_idPKINTUnique submission row ID
lead_idVARCHAR(20)Lead identifier from Meta lead capture
form_idVARCHAR(20)Lead form identifier
campaign_idINTAssociated ad campaign
submitted_atTIMESTAMPTime the lead was submitted
ingested_atTIMESTAMPTime the row landed in the warehouse
emailVARCHAR(100)Lead email address
phoneVARCHAR(20)Lead phone number
source_surfaceVARCHAR(30)Meta surface where the lead originated
campaigns
ColumnTypeDescription
campaign_idPKINTCampaign identifier
advertiser_idINTOwning advertiser
campaign_nameVARCHAR(100)Campaign name
statusVARCHAR(20)Campaign status
start_dateDATECampaign start date
advertisers
ColumnTypeDescription
advertiser_idPKINTAdvertiser identifier
advertiser_nameVARCHAR(100)Advertiser name
verticalVARCHAR(50)Advertiser industry
regionVARCHAR(30)Primary region
Tableslead_submissionscampaignsadvertisers
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results