MySQL get missing IDs from table

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)

Hope this link also helps
http://www.codediesel.com/mysql/sequence-gaps-in-mysql/

Leave a Comment