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 trialjames white
78,399 PointsBummer! Your query didn't perform the correct count. (wrong diagnostic message)
Link to challenge:
Challenge Task 1 of 2
In the library database, how many books are with the genre of "Science Fiction"?
Alias the result as scifi_book_count.
I used this code:
SELECT COUNT(genre) FROM books WHERE genre = "Science Fiction";
..which gave this result:
COUNT(genre)
6
Error message shown:
"Bummer! Your query didn't perform the correct count."
The actual code answer was this:
SELECT COUNT(genre) AS scifi_book_count FROM books WHERE genre = "Science Fiction";
which gave this result:
scifi_book_count
6
So you see the count value of '6' was output for both sets of code,
negating {in my view} the "Bummer! that 'Your query didn't perform the correct count.' "
.
(Although I know in this case it might just have been a situational/database coincidence that
'COUNT(genre)' just happened to equal to 'scifi_book_count' --that they both had a value of 6)
.
However, if you compare the difference between the sql that works (passes the challenge)
and the sql code that doesn't you'll see the first is the missing alias ('AS scifi_book_count')
So the Bummer diagnostic message (to be truly useful) should have been something like:
"You are missing the alias code"
Once I realized the original Bummer diagnostic message was not correct
in failing to point out that the key to getting the 'correct count' was
actually some missing SQL alias code then
I was easily able to solve the second part of the challenge as well with:
SELECT COUNT(author) AS jk_book_count FROM books WHERE author = "J.K. Rowling";
Note:
the use of the keyword 'DISTINCT' (as shown in the previous/accompanying video) doesn't seem to be needed.
6 Answers
Andrew Winkler
37,739 PointsYes. The code errors are a little bit hokey. I'm glad you figured out the correct code is:
SELECT COUNT(*) AS scifi_book_count FROM books WHERE genre = 'Science Fiction';
And
SELECT COUNT(author) AS jk_book_count FROM books WHERE author = "J.K. Rowling";
Jonathan Friberg
7,765 PointsYummmmm <3
Emmet Lowry
10,196 Pointsgood answers
james white
78,399 PointsThanks Andrew,
But I did get the correct answer (eventually)
I just wanted to make sure the challenge diagnostic was changed
to indicate/reflect that the issue with my first set of sql code was
that an alias was missing, not that the count was wrong.
Andrew Winkler
37,739 PointsYeah, I think I started answering your question before you were done editing it. Originally, it was an open ended question about the error code, then by the time I submitted my answer you had updated your question with a self-supplied-solution. Props! I updated/edited my response in series.
james white
78,399 PointsTo Andrew - no biggie..that sort of thing happens all the time on programming
(thanks for the quick, realtime response, though..)
Something else weird --
It most of the other courses if you press the "Get Help" button
it correct assigns your question to the course/syllabus.
For this 'Reporting with SQL' course that syllabus group is:
https://teamtreehouse.com/community/syllabus:2362
However I find I now have to go the long way around and select the "Get Help"
from the video previous to the challenge to get the question
to be assigned to threads specifically devoted to the course
and not just to the "Databases" forum (in general).
I wonder if this is something new that is going to be applicable to all courses
(going forward from this point) or just a one-time "oops!" for this course
(which already has had some issues):
Typo 1: https://teamtreehouse.com/community/typo-in-teachers-notes
Type 2 (should have been addresses, not customers): https://teamtreehouse.com/community/sql-error-no-such-column-firstname-resolved
Note: This was the thread that got 'orphaned' out of the course syllabus forum
even though I used the "Get Help" button on the challenge question page.
Kaisma Penn-Titley
PHP Development Techdegree Graduate 20,208 PointsThis worked for me.
SELECT COUNT(*) AS scifi_book_count FROM books WHERE genre = "Science Fiction";
Shikha Sitaula
3,443 PointsIt's kinda weird, I tried aliasing without quotes, it didn't work and then added quotes only then it worked! Other than that, I didn't change anything. And for the second code I did exact same as 1st but it didn't work again. I don't what's going on!! My bad!!
A X
12,842 PointsA X
12,842 PointsHi James, Thanks for pointing out about the error language being incorrect. I kept thinking we would need to incorporate DISTINCT into the second part of the challenge, and I was surprised that we didn't need to as well. Thanks also for providing the correct answer and a link to the challenge. If I could rate your post up I would!