extract query value from a variable in mysql

1

I have a query in a mysql trigger with a query similar to

BEGIN
    set @correos=(select correo from tabla_correos group by correo)
END

the table has the following structure and information

|     tabla_correos      |
-------------------------
|[email protected]         |
|[email protected]        |

in the end I want the emails to result in the following way

"[email protected],[email protected]"

but I do not know how to concatenate the emails as a string in a new variable, I do not know how to extract each value, I have been reviewing the documentation for days but I am lost, could you help me?

    
asked by Fernando Tovar 19.12.2017 в 22:34
source

1 answer

1

What you can do is concatenate the emails directly into the query using the group_concat :

select group_concat(distinct correo)
  from tabla_correos

This once returns all the emails separated by commas.

The group_concat function accepts other options if you need to separate the values differently or in a specific order.

    
answered by 20.12.2017 / 19:08
source