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

drstrangequark
drstrangequark
8,273 Points

I'm not sure what the problem with my query is

The task is:

In the library database, how many books are with the genre of "Science Fiction"? Alias the result as scifi_book_count. The books table has the columns id, title, author, genre and first_published.

I keep getting the error saying that my query didn't return the correct count but I don't know where my query is incorrect:

SELECT COUNT(*) FROM books AS "scifi_book_count" WHERE genre = "Science Fiction";

2 Answers

Patrik Horváth
Patrik Horváth
11,110 Points

hi, this part is wrong:

FROM books AS "scifi_book_count"

Query looks like this also use LIKE becau = is not always perfect

SELECT colName AS whot FROM tableName WHERE ...
drstrangequark
drstrangequark
8,273 Points

Yup that did it. Thanks!

Eli De Leon
PLUS
Eli De Leon
Courses Plus Student 1,758 Points

I had the same issue. I forgot the AS command has to come right after a function. This is what worked for me:

SELECT COUNT(title) AS "scifi_book_count" FROM books WHERE genre ="Science Fiction";