Method 1:
Copy codeThe Code is as follows:
Select top page size *
FROM table1
WHERE id NOT IN
(
Select top page size * (page-1) id FROM table1 order by id
)
Order by id
Method 2:
Copy codeThe Code is as follows:
Select top page size *
FROM table1
WHERE id>
(
Select isnull (MAX (id), 0)
FROM
(
Select top page size * (page-1) id FROM table1 order by id
)
)
Order by id
METHOD Two reverse order:
Copy codeThe Code is as follows:
Select top page size *
FROM table1
Where id <=
(
Select isnull (MIN (ID), (select max (ID) FROM table1 ))
FROM
(
Select top (page size * (page size-1) id from tbl_files ORDER BY ID DESC
)
)
ORDER BY ID DESC
Method 3
Copy codeThe Code is as follows:
Select top page size *
FROM
(
SELECT ROW_NUMBER () OVER (order by id) AS RowNumber, * FROM table1
)
WHERE RowNumber> page size * (page number-1)
Paging solution 2: (using more than ID and select top pages) is the most efficient. You need to splice an SQL statement
Paging solution 1: (using Not In and select top pages) The efficiency is second, and SQL statements need to be spliced.
Paging solution 3: (using SQL cursor Stored Procedure paging) The efficiency is the worst, but the most common
PS: these three solutions are found on the Internet. When paging is performed, solution 2 is selected. It is found that the directly applied statements cannot meet the requirements, because they need to be sorted in reverse order according to the posting order, that is, the latest posts need to be arranged at the beginning, so we changed the order to reverse order based on solution 2, hoping to help you.