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 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,365 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,365 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?