select a.id
from 
(select rownum id from all_objects where rownum < (select max(tb_id) from  b) a,
 table1 b,
where a.id not in( select tb_id from b)
  -- 数据量大时,运行速度会慢

解决方案 »

  1.   

    找一個記錄有和tb_id的最大值一樣記錄多的表,然後讓rownum minus本表tb_id即可
      

  2.   

    lianhg(lianhg)的第一行:select distinct(a.id)
      

  3.   

    能不能把你的设计思想说一下,看从根本上解决问题是否可行?
    否则建一张连续序号的表,最大序号与max(tb_id)相同,再做比较
      

  4.   

    lianhg的方法可行,但是你要保证all_objects的记录数要大于table1的tb_id最大值select distinct a.id from (select rownum id from (任意表名) where rownum < (select max(tb_id) from b) a where not exists(select 1 from b where a.id != b.id)
    这里任意表名要求该表的记录数大于b表的最大tb_id值
      

  5.   

    MSSQL,如果你的最大值不是特别大select * from (
    Select top 30 (select sum(1) from sysobjects where name<= a.name)-1 as id from sysobjects a
    ) tmp
    where id not in (select id from t)
      

  6.   

    only 9i:select b.id
    from table1 a, 
    left out jion (select rownum id from all_objects 
          where rownum <= (select max(tb_id) from table1 ) ) b
      on (a.tb_id = b.id)
    where a.tb_id is null ;没有测试环境,不知是否可行