i have a sql query:
select id, name from table order by name
result looks like this:
52 arnold
33 berta
34 chris
47 dori
You don't mention which RDBMS you're running, but if you're using SQL Server 2005 or greater, you can employ the ROW_NUMBER() function - like this:
SELECT id, name, ROW_NUMBER() OVER (ORDER BY name) AS RowNumber
FROM MyTable
Then, to fetch a given row, you can use a derived table or a common table expression - like this:
;WITH NumberedRows
AS
(SELECT id, name, ROW_NUMBER() OVER (ORDER BY name) AS RowNumber
FROM MyTable)
SELECT RowNumber FROM NumberedRows WHERE id = 47
To sort out "which page" the record is on, you would need to divide the row number by the number of records per page, and round up to the nearest integer.