CREATE TABLE `example_doc` (
`example_id` int(10) unsigned NOT NULL,
`doc_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`example_id`,`doc_id`)
)
CREATE TABLE `example` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
)
CREATE TABLE `doc` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
)
SELECT e.`name`, GROUP_CONCAT(d.`name`)
FROM example_doc ed
JOIN example e ON e.`id` = ed.`example_id`
JOIN doc d ON d.`id` = ed.`doc_id`
GROUP BY ed.`example_id`;