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,403
  • 1
  • 8
  • 15

2 Answers2

0

Use GROUP_CONCAT()

select group_concat(firstname separator '###') as firstnames,
       group_concat(lastname separator '###') as lastnames
from your_table
juergen d
  • 195,137
  • 36
  • 275
  • 343
0

Use:

select GROUP_CONCAT(firstname SEPARATOR "###") as firstname,
       GROUP_CONCAT(lastname SEPARATOR "###") as lastname
from tblname
Denis de Bernardy
  • 72,128
  • 12
  • 122
  • 148