Find the missing numbers in a given range
In postgresql:

CREATE TABLE ranges
(n1 int,
n2 int);

INSERT INTO ranges
VALUES (9,10),(11,19),(29,44),(45,51),(56,60);

SELECT n FROM ranges
RIGHT JOIN generate_series(15,60) n
ON (n1 &lt;= n AND n &lt;= n2) WHERE n1 IS NULL;