티스토리 뷰

MSSQL

MSSQL 페이징 쿼리

IT 2010. 12. 13. 16:58

SELECT * FROM 테이블명  WHERE thread in
 ( SELECT TOP 20 thread FROM 
 ( SELECT TOP 1020 thread FROM 테이블명 ORDER BY thread DESC ) AS A ORDER BY thread ASC ) 
ORDER BY thread DESC

해석)
첫번째 Sub Query : SELECT TOP 1020 thread FROM 테이블명 ORDER BY thread DESC
=> thread 번호 : 1 ~ 1020 (Top 1020)
=> thread 번호 : 1020 ~ 1 (ORDER BY thread DESC)

두번째 Sub Query : SELECT TOP 20 thread FROM (첫번째 Sub Query : 1020~1) AS A ORDER BY thread ASC
=> thread 번호 : 1020 ~ 1001 (Top 20)
=> thread 번호 : 1001 ~ 1020 (ORDER BY thread ASC)

1001,1002, ~ 1020까지 20개 추출
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31