不使用select top 100 * from table order by id desc 当表的数据量比较大时,上10万条时,使用这条语句查询速度就很慢。。
还没有其他的方法??
寻求sql高手

解决方案 »

  1.   

    create index ix_tb_id on tb(id desc)   --为ID创建索引
      

  2.   

    在ORDER BY 字段 上加索引!!!
      

  3.   

    给order by的字段加index,然后用top应该是最快的方法了吧。
      

  4.   

    1.加索引
    2.select * from table where id > (select max(id)-100 from table )
      

  5.   

    select top 100 * from table where id>(select MAX(id)-100 from table)
    哎,思路就是这样 貌似还是要排序
      

  6.   

    加索引解决不了问题
    那个排序可是全表扫描呀, 数据量大简直是灾难
    ID是递增的话,可能参考如下, 如果ID加上索引, 当然非常快
    select z.* 
    from table as z,
    (select (max(id) - 100) as BegID 
    from table
    ) as m
    where z.ID >= m.BegID 
    order by z.id desc