Home > Blockchain >  How to concatenate values of a string in MySQL
How to concatenate values of a string in MySQL

Time:05-10

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?

CodePudding user response:

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

CodePudding user response:

Do you mean?

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