views:

92

answers:

2

I have table with 50 entries (users with such details like Name Surname Location etc)

I want to create a query that give me users from row 1 to row 10. Then another query that give me users from 11 to 20 and so on.

Is there any way how to do that?

Thanks

+1  A: 

For those who don't feel like clicking through: the solution is to add row numbers to the resultset (using the "ROW_NUMBER() OVER (...)" syntax) and then refer to that row number column in a WHERE clause. Like:

SELECT 
    *,
    ROW_NUMBER() OVER (ORDER BY LastName, FirstName) AS RowNumber
  FROM
    Table
  WHERE
    RowNumber > 10 
    AND RowNumber <= 20

The 10 and 20 can then be parameters for the start and stop record.

Ian Varley