Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Finding Duplicate Records in SQL

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

Your question is Finding Duplicate Records in SQL. 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

Smc³ CarrierConnect receives transaction feeds that may contain repeated posted transactions. Write a PostgreSQL query to identify duplicate transaction records for reconciliation.

A transaction is considered a duplicate when another posted transaction has the same customer_id, merchant_id, transaction_date, amount, and currency. The unique transaction_id is not part of the duplicate definition. Treat matching NULL merchant IDs as the same value.

Requirements

  1. Consider only transactions where status = 'posted'.
  2. Return every transaction belonging to a duplicate group, along with the number of records in that group.
  3. Include the merchant name when available, retain transactions whose merchant ID is NULL or has no matching merchant, and order results by customer_id, transaction_date, and transaction_id.

Schema

transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
customer_idINTCustomer associated with the transaction
merchant_idINTMerchant identifier
transaction_dateDATEDate the transaction was recorded
amountNUMERIC(12,2)Transaction amount
currencyVARCHAR(3)ISO currency code
statusVARCHAR(20)Transaction processing status
merchants
ColumnTypeDescription
merchant_idPKINTUnique merchant identifier
merchant_nameVARCHAR(100)Merchant display name
Tablestransactionsmerchants
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results