建表 TEST1
CREATE TABLE `TEST1` (
`ID` int(11) NOT NULL,
`IID` varchar(200) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
结果:
建表TEST2
CREATE TABLE `TEST2` (
`ID` int(11) NOT NULL,
`name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
结果:
需要查询:TEST1表中IID每个数字所关联的内容
SELECT
a.ID ,( SELECT GROUP_CONCAT( `name` ) FROM TEST2 WHERE FIND_IN_SET( id, a.IID ) > 0 ) AS participant
FROM
TEST1 a,
TEST2 b
WHERE
a.IID = b.id
结果: