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 Aggregate and Numeric Functions Counting Results

COUNTING RESULATS

what is worng with this quairy ?

SELECT count(*) FROM books WHERE genre = Science Fiction ORDER BY id LIMT= 1;

4 Answers

Grigorij Schleifer
Grigorij Schleifer
10,364 Points

Hi Barak, a couple of issues.

You are not expected to LIMIT and order the query for this challenge.

I would suggest this code:

SELECT count(*) AS scifi_book_count -- alias your result as scifi_book_count
FROM books
WHERE genre = "Science Fiction";  -- here we need quotation marks to reference the genre

You dont need quotation marks if you reference a column name, but sinse the different genres are stored as text you need them.

Does this answer your question? Happy quering ...

ok. but isnt the AS alias, need to be like " the orignal name then the AS and then come scifi_book_count"?

great thanks!

Grigorij Schleifer
Grigorij Schleifer
10,364 Points

I am happy to help. Just shout out here in the forum :)

Why do I put the As next to the count ? How does it know that it belongs to the genare and not to other coulm?

like how does it replace the genre with the new alias , how does it know?