示例代码:
CREATE TABLE groups ( id INT PRIMARY KEY, name VARCHAR(50) );
CREATE TABLE contacts ( id INT PRIMARY KEY, name VARCHAR(50) );
CREATE TABLE group_contact ( group_id INT, contact_id INT, FOREIGN KEY (group_id) REFERENCES groups(id), FOREIGN KEY (contact_id) REFERENCES contacts(id) );
SELECT groups.name, GROUP_CONCAT(contacts.name SEPARATOR ',') AS contacts FROM groups JOIN group_contact ON groups.id = group_contact.group_id JOIN contacts ON group_contact.contact_id = contacts.id GROUP BY groups.id;