views:

9272

answers:

5

Basically the question is how to get from this:

id    string
1          A
1          B
2          C

to this:

id    string
1          A B
2          C
+23  A: 

SELECT id, GROUP_CONCAT(string SEPARATOR ' ') FROM table GROUP BY id;

http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat

Scott Noyes
+4  A: 

SELECT id, GROUP_CONCAT( string SEPARATOR ' ') FROM table GROUP BY id

More details here.

Graeme Perrow
You were slightly faster than Scott Neyes, but I decided to accept his answer. With ~25 rep points it makes a difference. Thanks.
phjr
No problem - I even upvoted his answer. :-)
Graeme Perrow
+3  A: 
SELECT id, GROUP_CONCAT(CAST(string as CHAR)) FROM table GROUP BY id

Will give you a comma-delimited string

Wayne
+1  A: 

GROUP_CONCAT has max data size limit 1024 and can be increased upto 67107840.How can we resolve this when large data retrieval is required.Can any on reply soon

A: 

SET group_concat_max_len=100000000

waqar alamgir