I have a table with 100 rows, and want to SELECT just a part of them(for example from row 20 to 30), like "paging" the SELECT.
which is an efficient way to do that in SQL Server 2008 R2?
I have a table with 100 rows, and want to SELECT just a part of them(for example from row 20 to 30), like "paging" the SELECT.
which is an efficient way to do that in SQL Server 2008 R2?
you can do it like this (assuming your table is called "tablename" ,your primary key is id, and you want rows 10 to 15).
select * from
(select *,row_number() over (order by id) as r from tablename)
t where r >10 and r < 15;
it may look inefficient but this is (sort of) how its done internally in linq.