select row_number() over() + max as id select left join where is null cross join (select coalece(max(id),0) as max