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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Get started
Deduplicate Late Meta Event Logs
00:00
5 left

Deduplicate Late Meta Event Logs

EasySQL · PostgreSQL

Problem

Meta’s event pipeline for Facebook activity can receive the same logical event multiple times, and some duplicates arrive late. Write a SQL query to return one canonical row per event_id, keeping the most recently ingested record.

Requirements

  1. Only consider events with a non-null event_id.
  2. Deduplicate by event_id across the full table, even if duplicates arrive on different ingestion dates.
  3. Keep the row with the greatest ingested_at for each event_id.
  4. If two rows for the same event_id have the same ingested_at, keep the one with the greater record_id.
  5. Return event_id, user_id, event_name, event_time, and ingested_at.
  6. Order the final result by event_id ascending.

Schema

meta_event_log
ColumnTypeDescription
record_idPKINTUnique identifier for each ingested row
event_idVARCHAR(50)Logical event identifier used to detect duplicates
user_idINTUser associated with the event
event_nameVARCHAR(50)Type of event generated on a Meta surface
event_timeTIMESTAMPTimestamp when the event occurred
ingested_atTIMESTAMPTimestamp when the event record arrived in the warehouse
source_surfaceVARCHAR(50)Meta product surface that emitted the event
Tablesmeta_event_log
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the one table are in the Question tab.

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.