I have a table containing a list of numbers. How do I find numbers that are missing from the table?
For instance:
numbers id
1 1
5 2
3 3
6 4
7 5
8 6
9 7
20 8
....
How can I find missing numbers? Like 4 and there are no numbers between 9 and 20.
I have tried nothing, but want to know.
How can I find missing numbers?You would need to define more closely which numbers are candidates Negative numbers? Only integer numbers? Lower / upper bound? The best answer depends on it. It also depends on the RDBMS yo actually use. Typically, we expect you to declare what you use - except you have reason to need a solution for multiple systems - or a DB-agnostic pure SQL solution? – Erwin Brandstetter Aug 09 '16 at 01:38