我有3张桌子
答案 0 :(得分:1)
USE group_concat
<强> SQL Fiddle Demo 强>
SELECT job_id, GROUP_CONCAT(fullname ORDER BY fullname ASC SEPARATOR ', ') AS applicants
FROM (
SELECT j.job_id, concat(f_name, ' ', l_name) fullname
FROM jobs j
join job_applicants ja
on j.job_id = ja.job_id
join applicants a
on ja.applicant_id = a.applicant_id
) as j
GROUP BY job_id
<强>输出强>
| job_id | applicants |
|--------|------------------------|
| 1 | emily swan, jhon twain |
| 3 | jhon twain |
| 4 | emily swan |