Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Duplicate Transaction Detection

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

Your question is SQL Duplicate Transaction Detection. 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

Write a SQL query to identify duplicate transactions within a specific timeframe to flag potential fraud.

For this exercise, analyze transactions from February 1 through February 28, 2025. Treat transactions as duplicates when they share the same account, merchant, amount, and timestamp. Return every transaction belonging to a duplicate set.

Output

  1. One row per duplicate transaction.
  2. Include transaction_id, account_id, account_name, merchant_id, amount, occurred_at, and duplicate_count.
  3. Order by occurred_at, account_id, and transaction_id ascending.

Schema

transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
account_idINTAccount associated with the transaction
merchant_idINTMerchant identifier
amountNUMERIC(10,2)Transaction amount
occurred_atTIMESTAMPTransaction timestamp
memoTEXTOptional transaction memo
accounts
ColumnTypeDescription
account_idPKINTUnique account identifier
account_nameVARCHAR(100)Account holder name
account_typeVARCHAR(30)Account category
Tablestransactionsaccounts
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results