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
SQL Query to Remove Duplicate Rows
00:00
5 left

SQL Query to Remove Duplicate Rows

MediumSQL · PostgreSQL

Problem

Write a query to identify and remove duplicate rows from a high-volume table.

Use payment_transactions. Treat payment_id as the unique row identifier and all other columns as the duplicate-detection fields. Retain the row with the smallest payment_id in each duplicate set.

Output

  1. One row per deleted duplicate, with column payment_id
  2. Include only rows removed by the query
  3. Sort by payment_id ascending

Schema

payment_transactions
ColumnTypeDescription
payment_idPKINTEGERUnique payment transaction identifier
merchant_idVARCHAR(30)Merchant identifier
customer_idVARCHAR(30)Customer identifier, when available
amountNUMERIC(12,2)Payment amount
currencyVARCHAR(3)ISO currency code
payment_statusVARCHAR(40)Current payment processing status
paid_atTIMESTAMPPayment completion timestamp
Tablespayment_transactions
Interviewer

Your question is SQL Query to Remove Duplicate Rows. Start with the requirements and the one table 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.