取sql表中n到m條記錄的語句

2021-04-19 08:01:56 字數 934 閱讀 9507

取n到m條記錄的語句

1. select top m * from tablename where id not in (select top n id from tablename)

2. select top m * into 臨時表(或表變數) from tablename order by columnname -- 將top m筆插入

set rowcount n

select * from 表變數 order by columnname desc

3. select top n * from

(select top m * from tablename order by columnname) a

order by columnname desc

4.如果tablename裡沒有其他identity列,那麼:

select identity(int) id0,* into #temp from tablename

取n到m條的語句為:

select * from #temp where id0 >=n and id0 <= m

如果你在執行select identity(int) id0,* into #temp from tablename這條語句的時候報錯,那是因為你的db中間的select into/bulkcopy屬性沒有開啟要先執行:

exec sp_dboption 你的db名字,'select into/bulkcopy',true

5.如果表裡有identity屬性,那麼簡單:

select * from tablename where identitycol between n and m

6.select top 20 * from a except all

select top 10 * from a   --取10到20

取n到m條記錄的語句

取n到m條記錄的語句1.select topm from tablename where id notin select topn id from tablename 2.select topm into 臨時表 或表變數 from tablename order bycolumnname 將top...

從表中取20 30條記錄的SQL語句

mysql的方法 mysql select from student limit 20,10 sid studentid age name 21 00010014 13 10014 0 22 00010015 16 10015 2 23 00010016 27 10016 0 24 00010017...

SQL取出第 m 條到第 n 條記錄的方法

從table 表中取出第 m 條到第 n 條的記錄 not in 版本 select top n m 1 from table where id not in select top m 1 id from table 從table表中取出第m到n條記錄 exists版本 select top n m...