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 trialJustin Thomas
10,461 PointsReally need help with task 2 of 2
Note: We will be writing ONLY the SQL query for this challenge. Imagine you're developing a Contacts application on a phone. You have a database with a phone_book table. It has the columns, first_name, last_name and phone. The phone has a technical limitation to show 20 contacts on a screen at a time. Write the SQL query to retrieve the 3rd page of results from the phone_book table. Contacts are ordered by last name and then first name.
1 Answer
Filipe Pacheco
Full Stack JavaScript Techdegree Student 21,416 PointsHi, Justin Thomas,
I don't know what exactly your struggle is, but here is some input.
You need to get the 3rd page of results when each page shows 20 items. So you have the LIMIT, but to get the OFFSET, you need to get the number of the page you want to retrieve minus 1 and multiply by the number of items shown per page. That would be (3-1)*20, which would be 40. It turns out to be LIMIT 20 OFFSET 40.
The trick here, though, is that it asks to sort first by last name and then by first name. So before the LIMIT, you can do ORDER BY last_name, first_name.
Hope that helps you.