1,
Select top pagesize newstitle
Form newsinfo where newsid not in
(Select top (page-1) * pagesize newsid from newsinfo
Where auditing = 1 and newsbreed = 'enterprise news 'order by newsid DESC)
And auditing = 1 and newsbreed = 'enterprise news 'order by newsid DESC
The page indicates the current page number, and the pagesize indicates the page size. The not in clause is used here, And the Sarg is not composite, but it is better than reading all the records at a time.
2. Sarg-compliantCode
There is also a better solution for my instance: Because the newsid field is an auto-incrementing field, the not in statement is modified as follows without affecting the result. But the speed has improved a lot.
Select top pagesize newstitle
Form newsinfo where newsid <
(Select Min (newsid) from (select top (page-1) * pagesize newsid from newsinfo where auditing = 1 and newsbreed = 'enterprise News' order by newsid DESC) as TB) and auditing = 1 and newsbreed = 'enterprise news 'order by newsid DESC
[Description]
For Web applications that use the paging function in multiple placesProgram, Changing SQL statements to stored procedures will be better.
Please participate in the discussion pageAlgorithmAnd share the solution with you.