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 trialBen Bastow
24,657 PointsI still dont understand GROUP BY
This may sound really stupid, but I don't understand the GROUP BY function in MYSQL and I have tried watching the video over and over again and I still don't understand it. Could someone explain how to use the GROUP BY function cause in the videos and everything I'm getting really confused.
3 Answers
James Anwyl
Full Stack JavaScript Techdegree Graduate 49,960 PointsThe best explanation I could find:
"The SQL GROUP BY clause is used in collaboration with the SELECT statement to arrange identical data into groups."
See this link (2nd example in particular)
Hope this helps :)
Ted Sumner
Courses Plus Student 17,967 PointsHere is an explanation with a working example database. The demonstration of the use is particularly helpful.
Ted Sumner
Courses Plus Student 17,967 PointsYour SQL query typically outputs to an array or similar storage method. You then want to use the output is some way, like displaying the information for the client. ORDER BY allows you to sort the data prior to putting it into the array. I am working on a project for a Cub Scout pack. Lets say that I want to list all the scouts in the pack by the highest badge they have completed. I would use order by to output the scouts in that order so I could easily place that data into the PHP for display. I could also sort by scouts that have not completed a certain badge, or by phone number, or by last name, or by first name, or any other data that is in the database. It saves having to manipulate a potentially large array.
Ben Bastow
24,657 PointsThank you for answering!! I understand ORDER BY now! However I still don't understand the GROUP BY method though, sorry!!
Ted Sumner
Courses Plus Student 17,967 PointsSorry, I answered the wrong questions. :)
majid majidi
Courses Plus Student 54 Pointsmajid majidi
Courses Plus Student 54 Pointshi this is my problem too ...