Databases SQL Reporting by Example Orientation: Selecting Data Listing Subjects

kevin hudson
PRO
kevin hudson
Pro Student 9,652 Points

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
200,778 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;
kevin hudson
PRO
kevin hudson
Pro Student 9,652 Points

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

Steven Parker
Steven Parker
200,778 Points

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

kevin hudson
PRO
kevin hudson
Pro Student 9,652 Points

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

Steven Parker
Steven Parker
200,778 Points

Did you mean ORDER BY?

SELECT DISTINCT name FROM subjects ORDER BY name;

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.