Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Detect Gaps in ID Sequence
00:00
5 left

Detect Gaps in ID Sequence

MediumSQL · PostgreSQL

Problem

Write a SQL query to identify gaps in a sequence of IDs.

Use the sequence_records table. Treat the complete sequence as every integer from the minimum non-null ID through the maximum non-null ID, inclusive. Ignore null IDs.

Output

  1. Return one row per missing ID with the column missing_id.
  2. Sort the results by missing_id in ascending order.

Schema

sequence_records
ColumnTypeDescription
record_keyPKINTUnique row identifier
sequence_idINTInteger ID whose sequence is being checked
Tablessequence_records
Interviewer

Your question is Detect Gaps in ID Sequence. 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.