Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Latest Row Per Group

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

Your question is Latest Row Per Group. 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

A Fivetran connector audit pipeline stores multiple sync records for the same source record. Write a PostgreSQL query that identifies duplicate groups and returns only the most recently synced row from each group.

Requirements

  1. Define duplicates using connector_id, source_table, and record_key.
  2. Return only groups containing at least two records.
  3. Select the latest row by synced_at, using id as a deterministic tie-breaker.
  4. Include the duplicate count and order results by connector, source table, and record key.

Schema

sync_records
ColumnTypeDescription
idPKINTEGERUnique sync record identifier
connector_idINTEGERFivetran connector identifier
source_tableVARCHAR(100)Source table captured by the connector
record_keyVARCHAR(100)Source record key used to define a duplicate group
payload_hashVARCHAR(64)Hash of the captured record payload
synced_atTIMESTAMPTZTimestamp when the record was synced
Tablessync_records
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results