Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Find Duplicates Without DISTINCT

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Find Duplicates Without DISTINCT. Start with the requirements and the one table on the right.

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.

Problem

Zebra Technologies receives device inventory data from systems supporting products such as Zebra TC53, TC58, and DS3678 devices. Duplicate imports can distort asset counts and downstream analytics.

Write a PostgreSQL query to find duplicate logical rows in device_inventory_imports without using DISTINCT. Treat rows as duplicates when all business columns match, excluding the surrogate import_id and ingestion timestamp.

Requirements

  1. Group by device_serial, device_model, firmware_version, warehouse_code, and lifecycle_status.
  2. Return only groups containing at least two records.
  3. Return the duplicate count and an ordered array of the corresponding import_id values.
  4. Treat NULL business values as equal for duplicate detection and order the output by duplicate count descending, then serial number.

Schema

device_inventory_imports
ColumnTypeDescription
import_idPKINTEGERUnique import record identifier
device_serialVARCHAR(30)Zebra device serial number
device_modelVARCHAR(40)Device model reported by the source system
firmware_versionVARCHAR(20)Reported firmware version
warehouse_codeVARCHAR(10)Warehouse holding the device
lifecycle_statusVARCHAR(20)Current lifecycle status
imported_atTIMESTAMPTZTimestamp when the source row was ingested
Tablesdevice_inventory_imports
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results