Skip to content
Advertisement

Tag: window-functions

Find first available value that doesn’t exist

I want to create table for book chapters where pk will be book_id and chapter_internal_number. I’m not sure how find next free chapter_internal_number value for new chapter insert (chapter can be deleted and it’s chapter_internal_number value should be reused). How to find first chapter_internal_number avaiable value for book? Avaiable value is next value that doesn’t exist in ASC order. Table

Advertisement