Databases Reporting with SQL Ordering, Limiting and Paging Results Paging Through Results

Yung Kazi
Yung Kazi
6,997 Points

Keyword OFFSET I am actually confused about what OFFSET is doing. [SOLVED]

My understanding is the syntax for using OFFSET is: SELECT <column> FROM <table> LIMIT <# of rows> ASC | DESC OFFSET <skipped rows> On the exercise, I used the limit as ten but then got confused on what my skipped rows would mean so I tried ten on that as well and that worked.

I want to understand why 10 worked for skipped rows and why using OFFSET is a good practice in SQL, thank you.

Showing a practice example would mean a lot.

2 Answers

Tommy Gebru
Tommy Gebru
28,819 Points

@Yung Kazi — Glad to help. You can mark a question solved by choosing a "best answer". And happy coding!

Tommy Gebru
Tommy Gebru
28,819 Points

So for this challenge, we are looking to display 10 queries at a time, with the limit by 10 statement and then of course we want to offset or begin the records on the second page of results, or rather we will exclude the first 10 :eyes:

SELECT * 
FROM books 
ORDER BY title ASC
LIMIT 10
OFFSET 10;

Therefore our sql code will select rows 11-20. This will be easier to experiment with in the SQL playground, when you can open up a recent workspace and try out the OFFSET keywords for real time results :wink: