SELECT t.id as task_id, GROUP_CONCAT(DISTINCT tf.id) as task_files_id, GROUP_CONCAT(DISTINCT tf.filename) as task_files_filename, GROUP_CONCAT(DISTINCT st.id) as subtask_id, GROUP_CONCAT(DISTINCT stf.filename) as subtask_file_filename FROM tasks t LEFT JOIN task_files tf ON tf.task_id= t.id LEFT JOIN sub_tasks st ON st.task_id= t.id LEFT JOIN sub_task_files stf ON stf.sub_task_id= st.id WHERE t.id=149 and t.company_id=1;