Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Deduplicate Transactions Across Channels

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

Your question is Deduplicate Transactions Across Channels. 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

Wayfair receives transaction records from multiple fulfillment channels, including Wayfair.com, the Wayfair app, and CastleGate. The same transaction may appear more than once when records are passed through multiple channels.

Write a PostgreSQL query that returns one canonical record for each non-null transaction reference, keeping the earliest transaction by timestamp. Include the number of records found for each transaction reference so duplicate groups can be identified.

Requirements

  1. Join transactions to their fulfillment channel names.
  2. Exclude records with a null transaction reference or no matching fulfillment channel.
  3. Use a window function to rank records by transaction_timestamp, using transaction_id as a deterministic tie-breaker.
  4. Return only the earliest record for each transaction reference, ordered chronologically.

Schema

payment_transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction record identifier
transaction_referenceVARCHAR(30)Business reference shared by duplicate records
order_idINTWayfair order identifier
amountDECIMAL(10,2)Transaction amount
transaction_timestampTIMESTAMPTime the channel record was received
channel_idINTReferences fulfillment_channels.channel_id
fulfillment_channels
ColumnTypeDescription
channel_idPKINTFulfillment channel identifier
channel_nameVARCHAR(50)Name of the fulfillment channel
Tablespayment_transactionsfulfillment_channels
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results