Subject Re: [firebird-support] Obtaining the minor number that does not exist
Author Ivan Prenosil
> Is it possible to obtain by means of a consultation the minor number that does not exist in a status of numbers?
>
> For Example:
>
> Table.Id
> 1
> 2
> 4
> 5
> 8
> 9
> ....
>
> select a.id from table a where a.id between 1 and 1000000
>
> Desire than of as a Result = 3

SELECT FIRST 1 ID+1
FROM (SELECT * FROM MyTable WHERE ID BETWEEN 1 AND 1000000 UNION SELECT 0 FROM RDB$DATABASE)
WHERE ID+1 NOT IN (SELECT * FROM MyTable)
ORDER BY ID;

Ivan
http://www.volny.cz/iprenosil/interbase/