ID值并不是连续的,如何读取到中间一段数据

例如有张表: table1
A:       ID           Name
          1             a
          2             b
          4             c
          6             d
          9             e
          11            f
          12            g
          15            h

ID值并不是连续的,如何读取到中间一段数据,例如第三行到第六行的记录?

这只是sql server下面可以:
select top 3 * from table1 where ID not in (select top 3 ID from table1)  (通过测试)


在mysql下面没有top关键字,但是我们可以用limit关键字:

select * from tb1 where id not in (select id from tb1 limit 10)

这题笔试常考,也很容易出错,网上答案乱七八糟,很多都是错的,所以最好还是亲历亲为。

posted @ 2012-05-10 21:16  宁静.致远  阅读(265)  评论(0编辑  收藏  举报