SELECT
c.controltype AS controltype,
c.coretype AS coretype,
g.name AS group_name,
core.name AS corename,
FROM
controls AS c
LEFT JOIN
groups AS g
ON
g.id = c.group_id
LEFT JOIN
(CASE
WHEN coretype = 'Программа'
THEN programs
WHEN coretype = 'Дисциплина'
THEN disciplines
WHEN coretype = 'Модуль'
THEN modules
END)
AS core
ON
c.core_id = core.id
LEFT JOIN
users AS u
ON
u.id = c.teacher_id
WHERE
id = :id