Response to: How to use NOT IN operator
Revision 5
While Shanalal Kasims solution is cool, it doesn't work when you have a larger gap in the sequence.
This is pure SQL and should work for all cases:
WITH M AS (
SELECT Max(SEQUENCE) s
FROM table1
WHERE id = 1
)
,numbers(n) AS
(
SELECT 1 AS n
UNION ALL
SELECT n + 1
FROM Numbers,m
WHERE n + 1 <= s
)
SELECT n
FROM numbers
WHERE n NOT IN (SELECT SEQUENCE FROM table1 WHERE id = 1)
Posted 13-Nov-12 22:35pm
by
Jörgen Andersson.