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

Zachary Wheeler
Zachary Wheeler
1,157 Points

Very First Reporting SQL Challenge Question

SELECT * FROM books ORDER BY first_published LIMIT ASC 5;

It asks us to input a code querying the first 5 in ascending order, but it says i'm missing WHERE. I don't know where to put the WHERE. Can you help me?

first, there is a mistake in your code, no biggie but:

SELECT * FROM books ORDER BY first_published ASC LIMIT 5;

second, the question is asking for fantasy books.

Sql queries are generally in this format (I find it easier to write my queries in this layout):

select
from
where
[other]
[limit]

So the answer would be something like:

SELECT * 
FROM books 
WHERE ...
ORDER BY first_published ASC 
LIMIT 5;

I will leave the rest for you to fill in ;)

Zachary Wheeler
Zachary Wheeler
1,157 Points

Thanks, I entered in the info and now it is saying that I didn't request 5? Here is what I have:

SELECT * FROM books WHERE genre ORDER BY first_published ASC LIMIT 5;

Let me know what I can fix. Thanks

3 Answers

Steven Parker
Steven Parker
215,984 Points

You didn't finish your WHERE clause.

I see that you started to write it, but you didn't finish testing for the Fantasy genre.

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

The incomplete test was rejecting every genre, producing 0 books instead of 5.

Zachary Wheeler
Zachary Wheeler
1,157 Points

oh that makes sense now. Thanks so much!

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

Nice answer Imad - concise. I like it.

Steven Parker
Steven Parker
215,984 Points

...and a loooong one, with a 6-month delay time. :wink: