Offset-Fetch in MS SQL Server Last Updated : 29 Jul, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report Suppose a table has 30 rows. A user wants to extract list of last 10 rows and skip topmost rows. To make job easier, the offset-fetch clause is used in the query. Syntax : order by column_list[ASC|DESC] Offset offset_row count{ROW|ROWS} Fetch{FIRST|NEXT} fetch row_count {ROW|ROWS} only Analysis of Syntax : Order by clause is mandatory to use alongside offset-fetch clause otherwise it results in an error. ASC arranges rows from ascending to descending order while DESC arranges rows from descending to ascending order. Offset skips number of rows specified in a table. Fetch returns number of rows after offset clause is being used. It returns specified number of rows. FIRST returns number of rows at start of table after offset is while NEXT returns consecutive rows after first set of rows. Example - Table - Student Roll number Name Course 111 Riya CSE 112 Apoorva ECE 113 Mina Mech 114 Rita Biotechnology 115 Veena Chemical 116 Deepa EEE If the user wants to skip first two rows and return rest of them, query is given as - select name, rollnumber, course from student order by rollnumber ASC offset 2 ROWS Output - Roll number Name Course 113 Mina Mech 114 Rita Biotechnology 115 Veena Chemical 116 Deepa EEE Offset skips number of rows specified in query while order by ASC arranges rows from ascending to descending order. If a user wants to skip first 6 rows and fetch the next ones, query is given as - select name, rollnumber, course from student order by roll number ASC offset 6 ROWS fetch FIRST 2 ROWS ONLY Output - Roll number Name Course 117 Vani Mech 118 Megha ECE Offset clause skips all rows specified in table while Fetch clause returns first two rows after offset clause. In the fetch clause, FIRST and NEXT can be used according to user's requirements. Offset clause is mandatory to use while fetch is optional for use in queries. Comment More infoAdvertise with us Next Article Order by in MS SQL Server M mangalgiaishwarya2 Follow Improve Article Tags : SQL DBMS-SQL SQL-Server Similar Reads Order by in MS SQL Server In this article, order by and terms related to order by will be discussed. Introduction - There are some instances where the tables are to be arranged in a chronological order. While the users use the select statement to retrieve rows, one cannot guarantee that the rows are arranged in an order. To 2 min read Introduction of MS SQL Server Data is a collection of facts and figures and we have humungous data available to the users via the internet and other sources. To manipulate the data, Structured Query Language (SQL) in short has been introduced years ago. There are different versions of SQL available in the market provided by diff 2 min read Select top in MS SQL Server Prerequisite - Select in MS SQL Server Suppose that a user wants to extract the top students from the whole institution but has to use some complex queries to extract the data. To avoid complexity, the user can use 'Select Top'. 'Select Top' extracts the limited number of rows. This results in accur 2 min read Joins in MS SQL Server A database comprises tables and each table in case of RDBMS is called a relation. Let us consider a sample database named University and it has two tables named Student and Marks. If a user wants to transfer a certain set of rows, insert into select statement is used along with the query. But if a u 2 min read How to Limit Rows in a SQL Server? To limit rows in SQL Server, use the TOP clause in the SELECT statement. Using the TOP clause in SQL Server, users can limit the number of rows in the results set. Here, we will understand how to limit rows in SQL Server with the help of different examples. Steps to Limit Rows in SQL ServerLet's che 3 min read Select Statement in MS SQL Server The SELECT statement in SQL Server is a foundational SQL command used for querying and retrieving data from one or more tables within a database. This command allows users to specify which columns and rows to retrieve and apply filters to focus on specific data and perform various operations to mani 4 min read Like