Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to skip the first n rows in sql query

Tags:

sql

I want to fire a Query "SELECT * FROM TABLE" but select only from row N+1. Any idea on how to do this?

like image 771
Ambkrish Avatar asked Apr 27 '15 11:04

Ambkrish


People also ask

How do I skip the first 10 rows in SQL Server?

The OFFSET FETCH clause allows you to skip N first rows in a result set before starting to return any rows. In this syntax: The ROW and ROWS , FIRST and NEXT are the synonyms. Therefore, you can use them interchangeably.

How do I skip a row in SQL query?

If you want to skip a certain number of rows but not limit how many rows to return, simply don't indicate a FETCH clause. For example, the following query skips 50 rows but doesn't limit the number of returned rows: SELECT orderid, orderdate, custid, empid FROM Sales.

How do I limit the first 5 rows in SQL?

Example - Using LIMIT keywordSELECT contact_id, last_name, first_name FROM contacts WHERE website = 'TechOnTheNet.com' ORDER BY contact_id DESC LIMIT 5; This SQL SELECT LIMIT example would select the first 5 records from the contacts table where the website is 'TechOnTheNet.com'.

How do I select all rows to except the first row in SQL?

The SQL EXCEPT operator is used to return all rows in the first SELECT statement that are not returned by the second SELECT statement. Each SELECT statement will define a dataset. The EXCEPT operator will retrieve all records from the first dataset and then remove from the results all records from the second dataset.


1 Answers

Use this:

SELECT * FROM Sales.SalesOrderHeader  ORDER BY OrderDate OFFSET (@Skip) ROWS FETCH NEXT (@Take) ROWS ONLY 

https://stackoverflow.com/a/19669165/1883345

like image 50
Majid Basirati Avatar answered Sep 29 '22 19:09

Majid Basirati