select start, stop from ( select m.id + 1 as start, (select min(id) - 1 from sequence as x where x.id > m.id) as stop from sequence as m left outer join sequence as r on m.id = r.id - 1 where r.id is null ) as x where stop is not null;