SELECT
o.`id_order_design`,
c.`name`,
o.`id_order_print`,
o.`type_product`,
o.`parameters`,
o.`date_order`,
GROUP_CONCAT(`name` SEPARATOR '|') AS `filelist`
FROM `orders_design` o
INNER JOIN `clients` c ON o.`id_client` = c.`id_client`
LEFT JOIN `files` f ON f.`id_order_design` = o.`id_order_design`
WHERE c.`id_manager` = '1'
GROUP BY o.`id_order_design`
UPDATE linestatuslog s
LEFT JOIN (SELECT * FROM linestatuslog ORDER BY startDate) n ON n.line = s.line AND n.startDate > s.startDate
SET s.endDate = IFNULL(n.startDate, '2016-01-01 00:00:00')
UPDATE linestatuslog s,
(
SELECT n1.*
FROM linestatuslog n1
UNION ALL
SELECT DISTINCT NULL as id,
n2.line,
NULL as status,
NULL AS user,
'2016-01-01 00:00:00' as startDate,
NULL AS endDate
FROM linestatuslog n2
ORDER BY startDate
) n
SET s.endDate = n.startDate
WHERE n.line = s.line AND n.startDate > s.startDate