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 trialJoshua Duval
9,167 PointsQuery didn't perform the correct count
This is for Code Challenge: Counting Groups, Challenge Task 1 of 2.
I've tried multiple approaches to figuring this out. For some reason, when I run the query, it shows a blank row below genre with a genre count of 0. I'm not sure if this is the reason why it's not working, or if for some reason it's my query that is wrong. I've tried the challenge on more the one computer in multiple browsers, I still can't seem to get it to work.
SELECT genre, COUNT(genre) AS genre_count FROM books GROUP BY genre;
1 Answer
codebyamir
12,108 PointsYou'll need to use COUNT(*) because that will also count NULL values whereas COUNT(genre) will not.
SELECT genre, COUNT(*) as genre_count from books GROUP BY genre;
Joshua Duval
9,167 PointsJoshua Duval
9,167 PointsThank you! I guess I didn't fully understand the difference in the two methods. It makes more sense, now!
Thomas Helms
16,816 PointsThomas Helms
16,816 PointsThat's definitely helpful. So paraphrasing and clarifying, for my edification, COUNT(genre) doesn't count the number of NULL genre entries, while COUNT(*) will count each instance of NULL.