From the course: SQL Practice: Intermediate Queries
Unlock this course with a free trial
Join today to access over 24,900 courses taught by industry experts.
Solution: List items in each order - SQL Tutorial
From the course: SQL Practice: Intermediate Queries
Solution: List items in each order
- [Instructor] To solve this challenge, I used GROUP_CONCAT, a function in MySQL and similar DBMSs that concatenates items based on their grouping. Microsoft SQL has a similar function called STRING_AGG, short for string aggregation, that works in the same way. If you use that, you'll need to have provided a separator, which to make the output match with the challenge request, should be a comma with no space following it. This function works together with a grouping term, which in this case is GROUP BY OrderID. Here we can see the different versions of MySQL and MS SQL syntax that have the same result that we're looking for. The challenge also asked for the list of items to be sorted alphabetically, and here with this MySQL syntax, I'm doing that with the ORDER BY D.Name in the GROUP BY function. Ascending is the default order here, so I can leave that off. But if I wanted to be explicit, I could add ASC as well. With MS…