Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,410 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 

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:

WHERE genre = 'Science Fiction'
ORDER BY first_published ASC