What is the fastest way to select a range of rows, let's say from 4.200.000 to 4.200.050, using SQL 2005? Suppose that I have 10 millions of rows.
On my own projects I use the following approach, but I'm not sure if this is the best practice
select * from
(
select
Column1, Column2, Column3
RowNumber = row_number() over (order by ID asc)
from
tblLogs
where
Column4 = @Column4 and Column5 = @Column5
) as tempTable
where tempTable.RowNumber >= @StartIndex and tempTable.RowNumber <= @EndIndex
With the code above I am tempted to say that tempTable will be a big table with one column containing all my IDs.
Is there anything faster ?
Don't think to make some workarounds using the ID column, this won't work, I delete rows from that table, so my IDs are not successive numbers.