1
2
3
4
5
6
7
8
SELECT a.id+1 AS start, MIN(b.id) - 1 AS end
FROM testtable AS a, testtable AS b
WHERE a.id < b.id
GROUP BY a.id
HAVING start < MIN(b.id)

-- http://stackoverflow.com/questions/12325132/mysql-get-missing-ids-from-table
-- http://www.codediesel.com/mysql/sequence-gaps-in-mysql/