Hi
I've got a single table, with a autonumber id (called id) ranging from 1 - 159270 so select max(id) from table1 returns 159270, but I think one of the records has been deleted, is there a simple way to find out which id is missing ?
Thanks
Hi
I've got a single table, with a autonumber id (called id) ranging from 1 - 159270 so select max(id) from table1 returns 159270, but I think one of the records has been deleted, is there a simple way to find out which id is missing ?
Thanks
Brute Force:
SELECT * FROM table T1
WHERE NOT EXISTS (SELECT * FROM Table T2 WHERE T2.ID = T1.ID - 1)
This should list rows JUST FOLLOWING the deleted ones.
Not working if more than one id is missing in a row... but fast:
select t1.id + 1 as missing_id
from mytable t1
left join mytable t2 on t1.id + 1= t2.id
where t2.id is null