-1

I have a table like this:

id  value  
1   a   
1   b   
2   c   
2   d   
2   e   

I want to combine rows with the same ids into one,here is what i want as result:

id  value  
1   a b 
2   c d e   
Mr Yar
  • 339
  • 1
  • 3
  • 10
  • 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) – Peyman Mohamadpour Feb 28 '17 at 08:08

1 Answers1

4

try this

select id,group_concat(value) as value from tb_name group by id;

if you want space instead ',' then try below query

select id,replace(group_concat(value), ',' ,' ') as value from tb_name group by id;
denny
  • 2,084
  • 2
  • 15
  • 19