Jakub Arnold
Jakub Arnold

Reputation: 87210

How to concatenate values from MySQL SELECT

Let's say I have

SELECT name 
FROM table

which gives me something like

foo
bar
baz

and I need to join all the values, to make it into one string like

foo bar baz

so I guess it would be something like

foreach row in (select ...) 
   var += row

but I have absolutely no idea how to write it in MySQL.

Upvotes: 1

Views: 1767

Answers (1)

Paul Dixon
Paul Dixon

Reputation: 300845

Use GROUP_CONCAT

SELECT GROUP_CONCAT(bar) FROM TABLE GROUP BY foo;

Upvotes: 6

Related Questions