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 Limiting Results

Cannot get the right SQL statement

Cannot get the right answer for a quiz

1 Answer

Tabatha Trahan
Tabatha Trahan
21,422 Points

For the first query you are looking for all columns in the books table where the genre is Fantasy, and you want the five oldest books, so order by publish date ascending, and limit to 5.

> SELECT * FROM books 
WHERE genre = 'Fantasy' 
ORDER BY first_published ASC 
LIMIT 5;

For the second query you are looking for the oldest Science Fiction book, so filter on genre with WHERE, ORDER BY first_published in ascending order, and LIMIT 1 to get one result, which will be the oldest Science Fiction book in the table:

SELECT * FROM books
WHERE genre = 'Science Fiction'
ORDER BY first_published ASC
LIMIT 1;