Fetch ids(Primary Key) from table where ids not available in table within range
SELECT n
FROM (
        SELECT 1000*n1+100*n2+10*n3+n4+1 n
        FROM 
                (
                SELECT 0 n1 UNION 
                SELECT 1 UNION 
                SELECT 2 UNION 
                SELECT 3 UNION 
                SELECT 4 UNION 
                SELECT 5 UNION 
                SELECT 6 UNION 
                SELECT 7 UNION 
                SELECT 8 UNION 
                SELECT 9 
                ) n1,
                (
                SELECT 0 n2 UNION 
                SELECT 1 UNION 
                SELECT 2 UNION 
                SELECT 3 UNION 
                SELECT 4 UNION 
                SELECT 5 UNION 
                SELECT 6 UNION 
                SELECT 7 UNION 
                SELECT 8 UNION 
                SELECT 9
                ) n2,
                (
                SELECT 0 n3 UNION 
                SELECT 1 UNION 
                SELECT 2 UNION 
                SELECT 3 UNION 
                SELECT 4 UNION 
                SELECT 5 UNION 
                SELECT 6 UNION 
                SELECT 7 UNION 
                SELECT 8 UNION 
                SELECT 9
                ) n3,
                (
                SELECT 0 n4 UNION 
                SELECT 1 UNION 
                SELECT 2 UNION 
                SELECT 3 UNION 
                SELECT 4 UNION 
                SELECT 5 UNION 
                SELECT 6 UNION 
                SELECT 7 UNION 
                SELECT 8 UNION 
                SELECT 9
                ) n4
        HAVING n &lt; (
                    SELECT MAX(student_id)
                    FROM Student
                   )
     ) numbers
LEFT JOIN Student ON student_id = n
WHERE student_id IS NULL


fiddle