Junior
Detailed answer
Paging
SQL & Databases
How do TOP and OFFSET FETCH differ?
Short answer: TOP (n) returns first n rows (optionally WITH TIES). OFFSET/FETCH is ANSI-style paging and requires ORDER BY. For keyset paging at scale, prefer seek-based pagination over deep OFFSET.
Sample solution
T-SQL
-- Page 3 of 10 SELECT EmpId, Name FROM Employees ORDER BY EmpId OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY; SELECT TOP (10) WITH TIES Name, Salary FROM Employees ORDER BY Salary DESC;
Deep OFFSET on large tables is expensive — mention keyset paging as a follow-up.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png