Use self-join
SELECT * FROM t t1 LEFT JOIN t t2 ON t2.ID = t1.ID + 1 WHERE t2.ID IS NULL
If there are no spaces, this returns only one row, for the last element in the table. You can even remove this line from the result set if you want to be smart, but that should give you this idea.
This method is especially useful if you want to work more with breaks. If not, the counting methods suggested by others are simpler.
user12861
source share