Question: Hi I have a table that has start and end columns that has the values 

```
Start   End
9       10
11      19
29      44
45      51
56      60

```

Now if I give the range like `15 to 60` I need to return the values that not being covered in the above range.

The output I am expecting is - `20,21,22,23,24,25,26,27,28,52,53,54,55` 

How can I retrieve this?

Answer: 
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 <= n AND n <= n2) WHERE n1 IS NULL;

```
I use tables that have a dimdate or count data to do this kind of calculation, but you could also do this using the identity column of a table that has at least 60 sequential identities.

Your other option is to select 60 or so rows from another table, and use the RowNumber() function. You would then right join to that select, and find the null values in your original list.

```
SELECT * 
FROM StartEnd (Your original table)
RIGHT JOIN (SELECT ROWNUMBER() as num 
            FROM SomeTable (any table with 60 rows) 
            WHERE SomeTable.column1 <= 60) 
    as SomeTableSubQuery on SomeTableSubQuery.num = StartEnd.numbers
WHERE StartEnd.numbers IS NULL

```

Sorry if this answer is convoluted. I can be more specific if you give me column names, etc.

EDIT: I thought you meant one column, not two, my bad.