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

SQL Count and Distinct task 2 of 2

I'm having trouble with this one https://teamtreehouse.com/library/reporting-with-sql/aggregate-and-numeric-functions/counting-results-2

I'm putting in this answer but I know I'm getting an error message because of the author's name.

SELECT COUNT(DISTINCT author) WHERE author = "J.K. Rowling" AS jk_book_count FROM books;

1 Answer

Steven Parker
Steven Parker
231,007 Points

The instructions say, "In the library database, how many books are with the author of "J.K. Rowling"?"

I see two issues with this query:

  • the task is a simple row count (of books), so you won't need "DISTINCT" or the "author" column
  • the WHERE clause should come last in the query

Got it now, thanks!!!