Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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
30,164 Points

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

Tommy Gebru
Tommy Gebru
30,164 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:

FROM books 

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: