asmith Posted August 23, 2009 Share Posted August 23, 2009 Hi, Just wondering if something like this is possible: SELECT field1 FROM table1, table3.member as membersField INNER JOIN (SELECT member FROM table2 ON table1.ID = table2.ID) as table3 ... So that instead of getting multiple rows as each member, it concat member filed in to one for each row of table1. Something like this: (For result) field1 membersField d1 tom, john, alex d2 richard, jack instead of d1 tom d1 john d1 alex d2 richard d2 jack Is it possible? Quote Link to comment https://forums.phpfreaks.com/topic/171495-solved-concating-results-as-one-field/ Share on other sites More sharing options...
kickstart Posted August 23, 2009 Share Posted August 23, 2009 Hi The function you need is GROUP_CONCAT Something like this SELECT a.field1, GROUP_CONCAT(b.membersField SEPARATOR ' ') FROM table1 a INNER JOIN table2 b ON a.ID = b.ID ORDER BY a.field1 All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/171495-solved-concating-results-as-one-field/#findComment-904383 Share on other sites More sharing options...
asmith Posted August 23, 2009 Author Share Posted August 23, 2009 Thanks a lot mate it is what I need. http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat Quote Link to comment https://forums.phpfreaks.com/topic/171495-solved-concating-results-as-one-field/#findComment-904388 Share on other sites More sharing options...
fenway Posted August 25, 2009 Share Posted August 25, 2009 Just be careful -- there's a maximum length to group-concat which is very short by default. Quote Link to comment https://forums.phpfreaks.com/topic/171495-solved-concating-results-as-one-field/#findComment-905939 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.