>For a given order of rows in a SQL Server table ( I.e. the natural order or the order an ORDER BY clause would generate ), is it possible to
efficiently query the Nth row in the table?
Bill,
There's no such thing as "the natural order" in the SQL Server. The data in the tables isn't stored in any particular order unless there's clustered index. What are you trying to do?
Anyway, Here's couple of tways to do that. If table has primary key, than it would be faster to get first PK and than join result back to the source table as shown in #2.
USE NorthWind
SELECT TOP 1 * FROM (
SELECT TOP 125 *
FROM [Order Details]
ORDER BY UnitPrice DESC
) dt1
SELECT *
FROM (
SELECT TOP 1 *
FROM (
SELECT TOP 125 OrderID, ProductID
FROM [Order Details]
ORDER BY UnitPrice DESC
) dt1
) dt2
JOIN [Order Details] odt
ON odt.OrderID = dt2.OrderID
AND odt.ProductID = dt2.ProductID
--sb--