-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

Community
  • 1
  • 1
prattom
  • 1,625
  • 11
  • 42
  • 67

1 Answers1

7

Use GROUP_CONCAT

SELECT GROUP_CONCAT(`groupID` SEPARATOR ',') FROM `tbl_groupassign` WHERE `memberID` = 'check1' GROUP BY `memberID`;
Maxim Krizhanovsky
  • 26,265
  • 5
  • 59
  • 89