How to find the missing number from a single table column using SQL?

advertisements

There are 999 rows and they have distinct 0-1000 number with one number missing in it. How to find that number using a SQL query?


Use something like this:

SELECT Min(ID) As firstMissedID
FROM (
    SELECT *, ROW_NUMBER() OVER (ORDER BY ID) rn
    FROM std) dt
WHERE rn < ID