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
18,392 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;