blog post

OFFSET excludes the first set of records.
OFFSET can only be used with an ORDER BY clause.
OFFSET with FETCH NEXT returns a defined window of records.
OFFSET with FETCH NEXT is great for building pagination support.

The SQL ORDER BY OFFSET syntax

The general syntax to exclude first n records is:
SELECT column-names
  FROM table-name
 ORDER BY column-names
OFFSET n ROWS

To exclude first n records and return only the next m records:
SELECT column-names
  FROM table-name
 ORDER BY column-names
OFFSET n ROWS
 FETCH NEXT m ROWS ONLY

SQL OFFSET-FETCH Examples

SELECT Id, ProductName, UnitPrice, Package
  FROM Product
 ORDER BY UnitPrice DESC
OFFSET 10 ROWS 

Problem: Get the 10th to 15th most expensive products sorted by price
SELECT Id, ProductName, UnitPrice, Package
FROM Product
ORDER BY UnitPrice DESC
OFFSET 10 ROWS
FETCH NEXT 5 ROWS ONLY

  • Share This Story


Pleas give your valuable comments to improve the contents.

about author

Atul kumar shukla


I'm Atul Kumar Shukla, working as a web developer.
Welcome to my Blog. This is my personal blog where i post my own questions and answers , articles about ASP.Net., SQL Server, HTML, CSS, Jquery and many more..

Visit Profile

Leave a comment

Name
E-mail
Url
Message

Get More Stuff
Subscribing to the TheOneblogs newsletter and get intersting stuff and updates to your email inbox.
Your Email

 

Style Switcher

Change Color

×! We use cookies to improve your user experience. More information