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 Reporting by Example Orientation: Selecting Data Listing Subjects

The first challenge should include GROUP BY

The first challenge should include GROUP BY because some subjects are repeated

5 Answers

Steven Parker
Steven Parker
229,657 Points

That's certainly one way to do it. An even easier way would be to use the DISTINCT keyword:

-- Which subjects are taught at Jefferson Middle School?
SELECT DISTINCT name FROM subjects;

I tried that first and no change then I tried GROUP BY and that worked. weird..

Steven Parker
Steven Parker
229,657 Points

Maybe a syntax issue? See the example I added to my answer.

Yes that was it. I would then use GROUP BY to order it

Steven Parker
Steven Parker
229,657 Points

Did you mean ORDER BY?

SELECT DISTINCT name FROM subjects ORDER BY name;

Yes silly me !

I'm definitely quite late to answering this question, but I don't think you'll need to use GROUP BY or DISTINCT here. While there are repeating values in the Name columns, they are unique in that they are taught for different grade levels. For example, there are three instances of the Math value, but they're designated for grades 6, 7, and 8.