The
OFFSET and FETCH both
are used with the ORDER
BY clause. They help to reduce the number of rows to be
returned by an applied query.
The
syntax of the
OFFSET and FETCH clauses: ORDER BY columns [ASC |DESC]
OFFSET offsetRowCount {ROW | ROWS}
FETCH {FIRST | NEXT} fetch_row_count {ROW | ROWS} ONLY
Note: You
cannot use
OFFSET and FETCH clauses
without the ORDER BY clause.
The
OFFSET and FETCH clauses
are preferred for implementing the query paging solution than the TOP clause
as it is efficient and easy to understand.
.
Examples of OFFSET and FETCH :
"select empId,empName,lastName from Employee_Master order by empId"
this query returned all the results stored in the table.
1. the below query skip the first 10 rows and fetch the next 10 rows as described.
Query:-
this query skip first 10 rows and fetch next 10 rows as already explained through diagram above
No comments:
Post a Comment