Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Finding Duplicate Records in SQL
00:00
5 left

Finding Duplicate Records in SQL

MediumSQL · PostgreSQL

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
Interviewer

Your question is Finding Duplicate Records in SQL. Start with the requirements and the two tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.