我无法将变量传递给子查询。
我有2个不同的表,需要让所有采访人员参加。
当前我的SQL
SELECT
empl.id AS id,
(SELECT
GROUP_CONCAT(interviewed_by SEPARATOR ', ')
FROM
(
SELECT
interview_old.interviewed_by
FROM
interview_old
WHERE
interview_old.empl = empl.id
UNION
SELECT
interview.interviewed_by
FROM
interview
WHERE
interview.empl = empl.id
)
as interviewed_by
) AS interviews
FROM
empl AS empl
这不是我的完整代码,所以我无法更改此部分
SELECT
empl.id AS id,
{only here allow insert custom sql}
FROM
empl AS empl
最佳答案
您的问题不是100%清楚,但是您可以首先将查询转换为不使用子查询,而仅将LEFT JOIN
与GROUP
结合使用:
SELECT
empl.id AS id,
GROUP_CONCAT(i.interviewed_by SEPARATOR ', ')
FROM
empl AS empl
LEFT JOIN (
SELECT empl, interviewed_by
FROM interview_old
UNION
SELECT empl, interviewed_by
FROM interview
) i
ON i.empl = empl.id
GROUP BY empl.id