Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL Duplicate or Missing Records
00:00
5 left

SQL Duplicate or Missing Records

MediumSQL · PostgreSQL

Problem

Write a SQL query to find duplicate or missing records in an operations dataset.

Use the expected_operations and operation_records tables. A duplicate is an operation identifier appearing more than once in operation_records. A missing record is an expected operation with no corresponding record.

Output

  1. Return one row per issue with issue_type, operation_id, and record_count.
  2. Use DUPLICATE or MISSING for issue_type; use zero for missing records.
  3. Order by issue_type, then operation_id.

Schema

expected_operations
ColumnTypeDescription
operation_idPKINTIdentifier of an operation expected in the dataset
operation_nameVARCHAR(100)Name of the expected operation
required_dateDATEDate on which the operation is expected
priorityVARCHAR(20)Operational priority
operation_records
ColumnTypeDescription
record_idPKINTUnique submitted record identifier
operation_idINTReferenced operation identifier
recorded_dateDATEDate the operation was recorded
statusVARCHAR(20)Submitted operation status
source_systemVARCHAR(30)System that submitted the record
Tablesexpected_operationsoperation_records
Interviewer

Your question is SQL Duplicate or Missing Records. 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.