Select rows where smaller row does not exist Consider the following table data:

ID NAME
1 Kshitiz 
2 Aman
5 Aakash
6 Manjeet


Here there are records missing between 2 and 5. What query can I use to select row 5 in this table?
Oracle supports LAG so you should be able to do something like.

SELECT T.ID, 
       T.NAME
FROM
(
SELECT ID, 
       NAME,
       LAG(ID) OVER (ORDER BY ID) AS PREVID
FROM YourTable
) T
WHERE ID &gt; PREVID + 1;


To compare the Id with the previous one and only return ones with a gap greater than 1.

(Untested as SQL Fiddle is currently returning errors when I try and create an Oracle Fiddle)