Subject | Re: Firebird get the list with all available id |
---|---|
Author | radubarbu84 |
Post date | 2013-01-30T10:40:01Z |
thank you all. I got also another solution, I will post it here maybe will help someone
with recursive numbers as (
select 1 number
from rdb$database
union all
select number+1
from rdb$database
join numbers on numbers.number < 1024
)
select n.number
from numbers n where not exists (select 1 from table t where t.id = n.number)
with recursive numbers as (
select 1 number
from rdb$database
union all
select number+1
from rdb$database
join numbers on numbers.number < 1024
)
select n.number
from numbers n where not exists (select 1 from table t where t.id = n.number)
--- In firebird-support@yahoogroups.com, "radubarbu84" wrote:
>
> In a table I have records with id's 2,4,5,8. How can I receive a list with values 1,3,6,7. I have tried in this way
>
> SELECT t1.id + 1
> FROM table t1
> WHERE NOT EXISTS (
> SELECT *
> FROM table t2
> WHERE t2.id = t1.id + 1
> )
>
> but it's not working correctly. It doesn't bring all available positions.
>
> Is it possible without creating another table?
>