What is the fastest way to select a range of rows, say, from 4.200.000 to 4.200.050 using SQL 2005? Suppose I have 10 million rows.
In 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 large single-column table containing all of my identifiers.
Is there anything faster?
Donβt think to make some workarounds using the identifier column, this will not work, I am deleting rows from this table, so my identifiers are not consecutive numbers.
source share