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 Deduping Vendor Imports
00:00
5 left

SQL Deduping Vendor Imports

MediumSQL · PostgreSQL

Problem

Write a query to find duplicate records in a vendor import table and keep only the most recent row.

Treat rows with the same vendor_code, invoice_number, and line_number as duplicates. If duplicate rows have the same import timestamp, retain the row with the highest import_id.

Output

  1. Return one retained row per logical vendor invoice line.
  2. Include import_id, vendor_code, invoice_number, line_number, amount, imported_at, and source_file.
  3. Order by vendor_code, invoice_number, line_number, and import_id ascending.

Schema

vendor_imports
ColumnTypeDescription
import_idPKINTUnique identifier for the imported row
vendor_codeVARCHAR(20)Vendor identifier from the import
invoice_numberVARCHAR(30)Vendor invoice identifier
line_numberINTLine number within the invoice
amountDECIMAL(12,2)Amount reported for the invoice line
imported_atTIMESTAMPTimestamp when the row entered the import table
source_fileVARCHAR(100)Name of the source file that supplied the row
Tablesvendor_imports
Interviewer

Your question is SQL Deduping Vendor Imports. 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.