Finding missing sequence no.
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: Finding missing sequence no.

  1. #1
    Join Date
    Oct 2001
    Location
    B'lore
    Posts
    1
    Hi,

    Can any one help me in finding missing no.s in a column
    USING SINGLE SQL .

    For eg column a contains 1,3,6,10

    I want the answer as 2,4,5,7,8,9

  2. #2
    Join Date
    Sep 2001
    Location
    UK
    Posts
    45
    You can use either of the 2 sql's

    1)select nvl(max(a.t),0) + 1 gapfrom,b.t-1 gapto
    from temp a ,temp b
    where a.t(+) < b.t
    group by b.t having nvl(max(a.t),0) < b.t -1;

    2) select a.t +1,b.t -1 from temp a,temp b where
    a.t +1 not in(select t from temp) and
    b.t=(select min(t) from temp where t > a.t)

    Cheers

  3. #3
    Join Date
    May 2000
    Posts
    58
    Here is another simple solution.
    select rownum from tab
    where rownum <= ( select max(x) from your_table )
    minus
    select x from your_table

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width