w3resource

AdventureWorks Database: Skip a number of rows from a sorted table

SQL Query - AdventureWorks: Exercise-35 with Solution

35. From the following table write a query in SQL to skip the first 10 rows from the sorted result set and return all remaining rows.

Sample table: HumanResources.Department


Click to view Full table

Sample Solution:

SELECT DepartmentID, Name, GroupName  
FROM HumanResources.Department  
ORDER BY DepartmentID OFFSET 10 ROWS;

Sample Output:

departmentid|name                      |groupname                           |
------------+--------------------------+------------------------------------+
          11|Information Services      |Executive General and Administration|
          12|Document Control          |Quality Assurance                   |
          13|Quality Assurance         |Quality Assurance                   |
          14|Facilities and Maintenance|Executive General and Administration|
          15|Shipping and Receiving    |Inventory Management                |
          16|Executive                 |Executive General and Administration|

SQL AdventureWorks Editor:

Practice Online


Contribute your code and comments through Disqus.

Previous: Using rank function with order by clause.
Next: Fetch rows from the middle of a sorted table.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Share this Tutorial / Exercise on : Facebook and Twitter

SQL: Tips of the Day

How to create a foreign key in SQL Server?

create table question_bank
(
    question_id uniqueidentifier primary key,
    question_exam_id uniqueidentifier not null,
    question_text varchar(1024) not null,
    question_point_value decimal,
    constraint fk_questionbank_exams foreign key (question_exam_id) references exams (exam_id)
);

Database: SQL Server

Ref : https://bit.ly/3sgS152