You can use FIND_IN_SET() and GROUP_CONCAT() ,
SELECT b.Group_ID, GROUP_CONCAT(a.name) name FROM Table2 b INNER JOIN Table1 a ON FIND_IN_SET(a.ID, b.Group_ID) > 0 GROUP BY b.Group_ID
OUTPUT
ββββββββββββ¦ββββββββββββββββββ β GROUP_ID β NAME β β βββββββββββ¬ββββββββββββββββββ£ β 1 β Person1 β β 2,3 β Person2,Person3 β ββββββββββββ©ββββββββββββββββββ
As a side element, this request may not work as efficiently as expected. Correctly normalize the table without saving comma-separated values.
UPDATE
GROUP_ID pretty confusing. Isn't that a PersonIDList ? Anyway, here is my suggested circuit design:
PERSON table
- PersonID (PK)
- Personname
- other columns.
GROUP table
- GroupID (PK)
- Groupname
- other columns.
Table PERSON_GROUP
- PersonID (FK) (at the same time PK with GroupID column)
- GroupID (FK)
source share