Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL for Duplicates and Trends
00:00
5 left

SQL for Duplicates and Trends

MediumSQL · PostgreSQL

Problem

Write a SQL query to identify duplicate transactions or analyze merchant transaction volumes over time at Visa.

For this exercise, identify duplicate transaction groups where the merchant, card token, amount, transaction date, and transaction type are identical. Exclude records without a card token and exclude duplicate groups whose merchant is not present in the merchant reference table.

Output

  1. One row per duplicate transaction group.
  2. Columns: merchant_name, card_token, amount, transaction_date, transaction_type, duplicate_count, and first_transaction_id.
  3. Include only groups with at least two transactions, ordered by merchant_name, transaction_date, amount, and card_token ascending.

Schema

visa_transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
merchant_idINTMerchant receiving the transaction
card_tokenVARCHAR(64)Tokenized card identifier
amountDECIMAL(12,2)Transaction amount in the transaction currency
transaction_dateDATECalendar date of the transaction
transaction_typeVARCHAR(30)Transaction operation type
visa_merchants
ColumnTypeDescription
merchant_idPKINTUnique merchant identifier
merchant_nameVARCHAR(150)Merchant display name
merchant_countryVARCHAR(2)ISO-style merchant country code
Tablesvisa_transactionsvisa_merchants
Interviewer

Your question is SQL for Duplicates and Trends. 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.