I am using SQL Server 2008 Enterprise on Windows Server 2008. I want to select result from top 11 to top 20 (e.g. I am only interested in the 11th to the 20th result). Any ideas how to write this query in tsql efficiently?
thanks in advance, George
Unfortunately SQL Server does not offer anything similar to MySQL's OFFSET
syntax. However, you may want to try using a derived table as follows:
SELECT some_field
FROM (
SELECT some_field, ROW_NUMBER() OVER (ORDER BY some_id) AS rownum
FROM table
) AS t
WHERE t.rownum BETWEEN 11 AND 20
See following solution is applicable only for SQL Server 2012 onwards.
Limit with offset in sql server:
SELECT email FROM myTable
OFFSET 10 ROWS
FETCH NEXT 10 ROWS ONLY;
//offset - no. of skipped rows
//next - required no. of next rows
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With