「SQLServer」top、offsetで検索結果件数を指定する

2021年9月1日

1.1件目からn件取得
書式
top 件数
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
select
top 3 uid
, username
, address
from
user_tbl
select top 3 uid , username , address from user_tbl
select
  top 3 uid
  , username
  , address 
from
  user_tbl

2.指定件目からn件取得
書式
offset 件目 rows fetch next 件数 rows only
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
select
*
from
user_tbl
order by
Id offset 4 rows fetch next 3 rows only
select * from user_tbl order by Id offset 4 rows fetch next 3 rows only
select
  *
from
  user_tbl
order by
  Id offset 4 rows fetch next 3 rows only

 

SQL

Posted by arkgame