2

Possible Duplicate:
MySQL Results as comma separated list
Combine Multiple child rows into one row MYSQL
SQL query to pivot a column using CASE WHEN

enter image description here

I want to make a query like this:

SELECT `name` AS `data` FROM `test_table` WHERE `level` = 1 ORDER BY `id`;

But I want it to answer me in only one line with a ',' ! Like this:

data = a,b,

Without using PHP, is it possible using only MySQL? How? Thank you.

Community
  • 1
  • 1
Reacen
  • 2,312
  • 5
  • 23
  • 33
  • Take a look : [http://stackoverflow.com/questions/1067428/combine-multiple-child-rows-into-one-row-mysql][1] [1]: http://stackoverflow.com/questions/1067428/combine-multiple-child-rows-into-one-row-mysql – swati May 04 '12 at 06:15

1 Answers1

4
SELECT  GROUP_CONCAT(name ORDER BY id SEPARATOR ';')
FROM    test_table
WHERE   level = 1
Quassnoi
  • 413,100
  • 91
  • 616
  • 614