1. Learn
  2. /
  3. Courses
  4. /
  5. Functions for Manipulating Data in SQL Server

Connected

Exercise

Aggregating strings

Usually, when we talk about concatenation, we mean putting together values from different columns. A common challenge for database developers is also to concatenate values from multiple rows. This was a task that required writing many lines of code and each developer had a personal implementation.

You can now achieve the same results using the STRING_AGG() function.

The syntax is: STRING_AGG(expression, separator) [WITHIN GROUP (ORDER BY expression)]

In this exercise, you will create a list with the origins of the beans for each of the following companies: 'Bar Au Chocolat', 'Chocolate Con Amor', 'East Van Roasters'.

Remember, for STRING_AGG() to work, you need to find a rule for grouping your data and use it in the GROUP BY clause.

Instructions 1/3

undefined XP
    1
    2
    3
  • Create a list with all the values found in the bean_origin column for the companies: 'Bar Au Chocolat', 'Chocolate Con Amor', 'East Van Roasters'. The values should be separated by commas (,).