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
Missing IDs SQL Query
00:00
5 left

Missing IDs SQL Query

EasySQL · PostgreSQL

Problem

Coupang's Rocket Delivery monitoring pipeline compares expected shipment IDs with shipment scan records. table_2 is the authoritative list of expected IDs, while table_1 contains observed scan events and may include duplicates, unmatched IDs, or NULLs.

Write a PostgreSQL query to identify every expected shipment ID that does not appear in the observed scan data.

Requirements

  1. Treat distinct non-NULL IDs in table_2 as the expected population.
  2. Treat an ID as observed when it appears at least once in table_1.
  3. Return each missing ID exactly once and include its expected record count from table_2.
  4. Exclude NULL IDs and IDs that appear only in table_1.
  5. Sort the result by shipment_id in ascending order.

Schema

table_1
ColumnTypeDescription
scan_idPKBIGINTUnique scan event identifier
shipment_idBIGINTShipment ID detected by the scan
scan_statusVARCHAR(20)Status recorded by the scan
table_2
ColumnTypeDescription
expected_record_idPKBIGINTUnique expected-shipment record identifier
shipment_idBIGINTAuthoritative expected shipment ID
fulfillment_centerVARCHAR(20)Coupang fulfillment center
Tablestable_1table_2
Interviewer

Your question is Missing IDs SQL Query. 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.