I have a table called chest
chest_id integer NOT NULL
index integer NOT NULL
I can get the next index by querying
select max(index) + 1 from chest group by chest_id
In case there is some index in the order that is not filled, how to get it? for example:
chest_id | index
0 | 0
1 | 1
2 | 2
1 | 4
How would I query to return the first available index? in the example above it would be 3. But if it was filled also the next available would be 5