Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I query OFFSET/ FETCH query on my SQL Server?

I want to run this query on my SQL Server as follows:

Microsoft SQL Server Management Studio 10.50.1600.1

But it can't recognize the OFFSET and so shows ERROR?

SELECT * FROM dbo.tbl_MatchDetail
ORDER BY MatchDetailID
OFFSET 10 ROWS
FETCH NEXT 10 ROWS ONLY;
like image 204
Milson Avatar asked Nov 03 '13 19:11

Milson


People also ask

What is offset fetch in SQL?

OFFSET FETCH is a feature added to the ORDER BY clause beginning with the SQL Server 2012 edition. It can be used to extract a specific number of rows starting from a specific index. As an example, we have a query that returns 40 rows and we need to extract 10 rows from the 10th row: 1.

What will be the syntax of the offset fetch clause in SQL?

The following are the syntax that illustrates the use of OFFSET and FETCH clause: SELECT * FROM table_name. ORDER BY columns [ASC |DESC] OFFSET no_of_rows_to_skip.

How do I create a fetch query in SQL?

FETCH is an SQL command used along with ORDER BY clause with an OFFSET(Starting point) to retrieve or fetch selected rows sequentially using a cursor that moves and processes each row one at a time till the number of rows mentioned in the query are displayed. With FETCH the OFFSET clause is mandatory.


2 Answers

OFFSET FETCH is a new feature added to Sql Server 2012 and does not exist in Sql Server 2008.

like image 92
Amir Keshavarz Avatar answered Sep 27 '22 21:09

Amir Keshavarz


Please be aware you will get an error even in 2014 if you don't have an order by. The offset must follow an order by statement.

like image 24
Dale Fraser Avatar answered Sep 27 '22 23:09

Dale Fraser