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

Chris Jones
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Jones
Java Web Development Techdegree Graduate 23,933 Points

Counting Groups - SQL

I must be missing something really obvious. Below is the challenge. This is challenge #2 of 2 called Counting Groups in the Reporting with SQL course.

In the library database there's a books table. There are id, title, author, genre and first_published columns. Write a query to count all the unique genres in the books table. Alias it as total_genres.

I've tried both of the answers below:

SELECT DISTINCT count(genre) AS total_genres FROM books
SELECT DISTINCT count(*) AS total_genres FROM books

I keep getting the same message: "Your query didn't perform the correct count."

Does anyone know what I'm doing wrong?

Thanks!

1 Answer

Umesh Ravji
Umesh Ravji
42,386 Points

Hi Chris, you have the DISTINCT/COUNT statement/function in the wrong order. First you have to select all of the DISTINCT genre columns, and then COUNT how many of them there are.