0

I want to know if there is any option to output multiple rows into a single row.

for example the regular select * from tbl_name will give a list of all records available in the table.

firstname    lastname
----------   ------------
Lepanto      Fernando
Lourdes      Brillianto
Gerald       Siluvai

Preferred output

firstname will have -> Lepanto###Lourdes###Gerald

lastname will have -> Fernando###Brillianto###Siluvai

Can we have some concatenation done to achieve the above.

Lepanto
  • 1,413
  • 1
  • 8
  • 15
  • Search for group_concat() or use any of the questions on the right hand side of your browser. –  Jun 12 '13 at 13:22
  • possible duplicate of [Can I concatenate multiple MySQL rows into one field?](http://stackoverflow.com/questions/276927/can-i-concatenate-multiple-mysql-rows-into-one-field) –  Jun 12 '13 at 13:22

2 Answers2

0

Use GROUP_CONCAT()

select group_concat(firstname separator '###') as firstnames,
       group_concat(lastname separator '###') as lastnames
from your_table
juergen d
  • 201,996
  • 37
  • 293
  • 362
0

Use:

select GROUP_CONCAT(firstname SEPARATOR "###") as firstname,
       GROUP_CONCAT(lastname SEPARATOR "###") as lastname
from tblname
Denis de Bernardy
  • 75,850
  • 13
  • 131
  • 154