Skip to content

1613. Find the Missing IDs 👍

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
WITH
  RECURSIVE Ids AS (
    SELECT 1 AS id
    UNION ALL
    SELECT id + 1
    FROM Ids
    WHERE id < (
        SELECT MAX(customer_id)
        FROM Customers
      )
  )
SELECT Ids.id AS ids
FROM Ids
LEFT JOIN Customers
  ON (Ids.id = Customers.customer_id)
WHERE Customers.customer_id IS NULL
ORDER BY 1;