'How to concatenate values of a string in MySQL

I'm trying to concat values column values in MySQL db but I get an error

FUNCTION sales.STRING_AGG does not exist

SELECT
    city, 
    STRING_AGG(email,';') email_list
FROM
    sales.customers
GROUP BY
    city;

What I'm I missing?



Solution 1:[1]

You need to use group_concat

SELECT  city, 
        group_concat(email) email_list
FROM customers
GROUP BY city;

DEMO

You can also order by inside of the group_concat() function like this:

group_concat(email order by email) email_list

Or change separator from default , to ;

group_concat(email order by email desc separator ';') email_list

Solution 2:[2]

Do you mean?

SELECT city, 
       GROUP_CONCAT(email) email_list 
FROM sales.customers 
GROUP BY city;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Ergest Basha