SELECT task.*,a.users_login AS createuser,a.users_id AS createuser_id,b.users_login AS respuser,
b.users_id AS respusers_id,b.users_role, contact.*,point.*,
company.*,d.sum_time,d.sum_text,task_status.*
FROM task
LEFT JOIN users a ON task_user_id=a.users_id
LEFT JOIN users b ON task_resp_user_id=b.users_id
LEFT JOIN `contact` ON contact_id=task_contact_id
LEFT JOIN `point` ON task_point_id=point_id
LEFT JOIN `company` ON task_company_id=company_id
LEFT JOIN `task_status` ON task_status_id = task_status
LEFT JOIN (
SELECT comment_task_id,sum(comment_time) AS sum_time,GROUP_CONCAT(comment_text) AS sum_text
FROM `comment`
GROUP BY comment_task_id
) d
ON d.comment_task_id = task_id
WHERE concat(contact_tel,' ',contact_name,' ',contact_sname,' ',contact_surname) LIKE '%%'
AND CONCAT(point_id,' ',point_name,' ',point_zona,' ',point_city,' ',point_street,' ',point_dom) LIKE '%%'
and task_resp_user_id = '13'
AND task_status = '1'
order by task_id desc
LIMIT 100
Проблема в конкретно в этой части запроса
LEFT JOIN (
SELECT comment_task_id,sum(comment_time) AS sum_time,GROUP_CONCAT(comment_text) AS sum_text
FROM `comment`
GROUP BY comment_task_id
) d
ON d.comment_task_id = task_id
Он сначала выбирает все строки этой таблицы и только потом присоединяет к основному запросу, надо как-то ограничить набор данных по comment_task_id который присутствует в этой же таблице, но этот вариант не работает
LEFT JOIN (
SELECT comment_task_id,sum(comment_time) AS sum_time,
GROUP_CONCAT(comment_text) AS sum_text
FROM `comment`
WHERE comment_task_id = task_id
GROUP BY comment_task_id ) d
ON d.comment_task_id = task_id