Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Missing IDs SQL Query

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

Your question is Missing IDs SQL Query. Start with the requirements and the two tables 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

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
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results