-2

I have two columns (groupID, memberID) in table and I execute following mysql query

select `groupID` from `tbl_groupassign` where `memberID` = 'check1';

which prints column groupID but I want to show groupID in single row with each groupID separated by comma. For example I get following result by executing above query

groupID

group1

group2

but I want show it as group1, group2

4

1 回答 1

7

Use GROUP_CONCAT

SELECT GROUP_CONCAT(`groupID` SEPARATOR ',') FROM `tbl_groupassign` WHERE `memberID` = 'check1' GROUP BY `memberID`;
于 2013-09-23T08:41:15.167 回答