select top 5 * from table1 order by id desc

解决方案 »

  1.   

    select top 5 * from table1 order by id desc
      

  2.   

    ORDER BY ID      -- 前5条
    ORDER BY ID DESC -- 最后5条
      

  3.   

    --如果是无序的就用临时表
    select identity(int,1,1) id,* into #aa from emp
    select top 5 from #aa order by id desc
      

  4.   

    --如果是无序的就用临时表
    select identity(int,1,1) id,* into #aa from emp
    select top 5 * from #aa order by id desc
      

  5.   

    select * from 
    (select top 5 * from table1 order by id desc) a
    order by id
      

  6.   

    select * from
    (select top 5 from table1 order by desc) a
    order by a.id
      

  7.   

    你们别瞎答好么,人家说的是标的最后5条记录,不是按某一字段排序后的最后五条
    faint.
    这种事是要写程序实现的。
      

  8.   

    按樓主的字面理解:如果表有indexs, 或有ID的話那麼用
    select * from 
    (select top 5 * from table1 order by id desc) a
    order by id
    示例中用的是ID
    也可以用indexs
    如果表中有時間字段,也可以用時間字段
      

  9.   

    你们别瞎答好么,人家说的是标的最后5条记录,不是按某一字段排序后的最后五条
    faint.
    这种事是要写程序实现的。
    ----------------
    不要这样对人,这样在这里得不到尊重,你只要按照搂主的意思给出你的方法以及交流下就可以。
      

  10.   

    同意 wzh1215(四脚蛇)的方法
      

  11.   

    我知道错了,在这里向大家道歉,请各位原谅。我觉得搂住的意思是得到表的最后5条记录,不是按某一字段排序后的最后五条。搂住的select top 5* from table1示例不要求有排序字段(当然,有排序字段会好办一些),如果我想得到第20到25条记录又怎么能仅靠排序解决问题呢。我以前做过一个网页,一页一页每页显示5条记录,确实是用编程实现的,不知是否还有其他办法。总之,在这里还是要向各位说声对不起,我是新来的,太冒失了,还请各位多多批评。