Subquery to String?

mysql, subquery

Solution

You can use the `group_concat` function:

SELECT group_concat(country, ', ') FROM countries WHERE id < 10

Problem

I have a table containing countries: ``` id country ------------ 0 Monaco 1 Mongolia 2 Montenegro 3 Morocco 4 Mozambique 5 Myanmar ``` I have a sub query that looks like this. ``` (SELECT country FROM COUNTRIES WHERE id < 10) AS ´Trip´ ``` I want to have that subquery to be formatted as a string like this: `'Monaco, Mongolia, Montenegro, Morocco, Mozambique, Myanmar'` Is that possible?

Original source