Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
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
Experiences
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
Build my plan
Deduplicating Streaming History
00:00
5 left

Deduplicating Streaming History

MediumSQL · PostgreSQL

Problem

Write a query to identify duplicate records in a user streaming history table and keep only the most recent entry.

Assume records are duplicates when they share the same user_id, content_id, and started_at. The most recent entry is the one with the greatest ingested_at; use record_id as a final tie-breaker.

Output

  1. Return one row per unique user, content, and start-time combination.
  2. Include record_id, user_id, content_id, started_at, ingested_at, and device_type.
  3. Order by user_id, content_id with nulls last, started_at, and newest ingested_at first.

Schema

user_streaming_history
ColumnTypeDescription
record_idPKINTUnique identifier for the ingested history record
user_idINTIdentifier of the streaming user
content_idVARCHAR(100)Identifier of the streamed content
started_atTIMESTAMPTime when the streaming event began
ingested_atTIMESTAMPTime when the record was loaded into the history table
device_typeVARCHAR(30)Device used for the streaming session
Tablesuser_streaming_history
Interviewer

Your question is Deduplicating Streaming History. Start with the requirements and the one table in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.