Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Detect Duplicate Records in SQL

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

Your question is Detect 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

Finacle transaction ingestion can receive the same banking transaction more than once from core banking, ATM, or mobile channels. Write a PostgreSQL query to identify duplicate active records in finacle_transaction_ingest.

Requirements

  1. Treat records as duplicates when customer_id, txn_reference, txn_date, amount, currency, and transaction_type match. A NULL reference must match another NULL reference.
  2. Include only records with processing_status of POSTED or PENDING; exclude reversed records.
  3. Return every duplicate record, its duplicate count, the customer name when available, and sort deterministically by customer, reference, date, and transaction ID.

Schema

finacle_transaction_ingest
ColumnTypeDescription
transaction_idPKBIGINTUnique ingested transaction record ID
customer_idVARCHAR(20)Finacle customer identifier
txn_referenceVARCHAR(40)Source transaction reference
txn_dateDATEBanking transaction date
amountNUMERIC(14,2)Transaction amount
currencyVARCHAR(3)ISO currency code
transaction_typeVARCHAR(20)Debit or credit
processing_statusVARCHAR(20)Processing state
source_systemVARCHAR(20)Originating channel or system
finacle_customers
ColumnTypeDescription
customer_idPKVARCHAR(20)Finacle customer identifier
customer_nameVARCHAR(120)Customer display name
segmentVARCHAR(30)Customer segment
Tablesfinacle_transaction_ingestfinacle_customers
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results