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 trialDerek Morse
1,776 PointsNOT understanding
SELECT COUNT genre FROM books GROUP BY genre_count;
2 Answers
Tomas Schaffer
11,606 PointsSELECT COUNT(genre) genre_count FROM books GROUP BY genre_count;
But what is the reason to group the results of one column? Because this query is the result of one record.
This Query counts the number of result.
SELECT COUNT(*) genre_count FROM books;
So this is the same with better performance because you dont select all data just counting rows of table:
SELECT COUNT(0) genre_count FROM books;
Tomas Schaffer
11,606 PointsI didn't see first time button to Challenge and didn't see whole question. The right Answer to Challenge is below Derek.
SELECT genre, count(0) as genre_count FROM books GROUP BY genre;
Steven Parker
231,184 PointsSteven Parker
231,184 PointsDid you actually try any of those as answers to the challenge?
Tomas Schaffer
11,606 PointsTomas Schaffer
11,606 PointsYou didn't put the link to challenge. I didn't even know thats from challenge. But i work with PostgreSQL. So post the link to challenge if you like to.
Steven Parker
231,184 PointsSteven Parker
231,184 PointsThe link to the challenge is the colored button in the upper right of this page that says "View Challenge".
The system put it there automatically when Derek created this question.
Tomas Schaffer
11,606 PointsTomas Schaffer
11,606 PointsOK I am sorry didnt se the button.This is the correct answer.
SELECT genre, count(0) as genre_count FROM books GROUP BY genre;