SKIP
SKIP in SQL is a clause used to exclude a certain number of rows from the initial selection of results. It's commonly used in coordination with the LIMIT command to facilitate pagination in the retrieval of query results.
Example
Output
Employee_Id | First_Name | Last_Name | Date_Of_Birth | Department |
---|---|---|---|---|
11 | John | Doe | 1985-02-15 | HR |
12 | Mary | Johnson | 1987-04-25 | Finance |
13 | James | Brown | 1990-05-30 | Marketing |
14 | Linda | Davis | 1989-02-15 | IT |
15 | Robert | Miller | 1988-08-08 | sales |
Explanation
In the given example, the OFFSET
keyword is used to skip the first 10 records in the employees
table. The LIMIT
keyword then selects the next 5 records. The ORDER BY
clause orders the records by employee_id
. So, this SQL query returns records from 11 to 15.
Example
Output
Explanation
This SQL Server specific statement sorts the ‘Employee’ table by ‘EmpID’ and skips the first 5 rows. After skipping, it fetches the next 10 rows. If the result set has less than 15 entries, fewer lines could be displayed.
Example
Output
Explanation
The SELECT statement above orders the rows in the employees
table by salary
in descending order. It then uses the FETCH NEXT
clause to skip the top 5 rows, resulting in the 6th to 10th highest-paid employees being displayed.