Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
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 feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Duplicate Transactions SQL
00:00
5 left

Duplicate Transactions SQL

EasySQL · PostgreSQL

Problem

Syfe's QA team needs to identify potentially duplicated entries in the user ledger before reconciliation. A transaction is considered duplicated when the same user has multiple ledger rows with the same transaction type, amount, currency, and timestamp. The transaction ID and processing status are not part of the duplicate definition.

Write a PostgreSQL query that returns every row belonging to a duplicate group and includes the user's email when available.

Requirements

  1. Use aggregation with GROUP BY and HAVING to identify duplicate transaction groups.
  2. Return the transaction ID, user ID, email, transaction attributes, and the number of rows in its duplicate group.
  3. Include ledger rows whose user record is unavailable, showing a NULL email.
  4. Order results by user_id, occurred_at, and transaction_id.

Schema

ledger_transactions
ColumnTypeDescription
transaction_idPKINTEGERUnique ledger row identifier
user_idINTEGERSyfe user identifier
transaction_typeVARCHAR(30)Ledger event type
amountNUMERIC(12,2)Transaction amount
currencyVARCHAR(3)ISO currency code
occurred_atTIMESTAMPTime of the ledger event
processing_statusVARCHAR(20)Processing state of the ledger row
external_referenceVARCHAR(50)Reference from the upstream payment system
users
ColumnTypeDescription
user_idPKINTEGERSyfe user identifier
emailVARCHAR(120)User email address
Tablesledger_transactionsusers
Interviewer

Your question is Duplicate Transactions 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.