Question: retrieve data between 100 and 200 entries in a table
Method 1: temporary table
Copy codeThe Code is as follows:
Select top 200 * into # aa from table order by time -- Insert the top m pen into the temporary table
Set rowcount 100
Select * from # aa order by time desc
-- Drop table # aa -- delete a temporary table
Method 2:
Copy codeThe Code is as follows:
Select top 100 * from
(Select top 200 * from table order by time asc)
Order by time desc
Method 3: not in
Copy codeThe Code is as follows:
Select top 100 * from v_company where (
Id not in
(Select top 100 id from v_company order by id asc)
) Order by id asc
Here we only list three methods I tested. There are other solutions that can be supplemented by experts. The efficiency of the three solutions is not the same. I always think that not in is not efficient, however, using not in here is the fastest speed. Please explain it. Thank you.