SELECT `a`.`id`, GROUP_CONCAT(`p`.`title`) FROM `table1` `a` LEFT JOIN `table2` `p` ON `p`.`code`=`a`.`code` GROUP BY `a`.`id`