SELECT
GROUP_CONCAT(list ORDER BY list ASC SEPARATOR ', ') AS selected,
tbl_borrow_logs.`user`,
tbl_borrow_logs.fullname,
tbl_borrow_logs.log_id,
tbl_borrow_logs.depart,
tbl_select_item.amount,
tbl_borrow_logs.tel1,
tbl_borrow_logs.tel2,
tbl_borrow_logs.obj,
tbl_borrow_logs.logs_status,
tbl_borrow_logs.loan_by,
tbl_borrow_logs.approve_by,
tbl_borrow_logs.start_date,
tbl_borrow_logs.end_date,
tbl_borrow_logs.date_receive,
tbl_borrow_logs.date_return,
tbl_borrow_logs.place,
tbl_borrow_logs.signature_user,
tbl_borrow_logs.signature_admin,
tbl_borrow_logs.signature_super_admin,
tbl_borrow_logs.return_signature_user,
DATEDIFF(end_date,start_date) AS totalday,
DATE_FORMAT(start_date,'%d') AS thaidate,
DATE_FORMAT(start_date,'%Y')+543 AS thaiyear,
DATE_FORMAT(start_date,'%H.%i') AS thaitime,
DATE_FORMAT(end_date,'%d') AS thaidate2,
DATE_FORMAT(end_date,'%Y')+543 AS thaiyear2,
DATE_FORMAT(end_date,'%H.%i') AS thaitime2,
DATE_FORMAT(date_receive,'%d') AS thaidate3,
DATE_FORMAT(date_receive,'%Y')+543 AS thaiyear3,
DATE_FORMAT(date_receive,'%H.%i') AS thaitime3,
DATE_FORMAT(date_return,'%d') AS thaidate4,
DATE_FORMAT(date_return,'%Y')+543 AS thaiyear4,
DATE_FORMAT(date_return,'%H.%i') AS thaitime4
FROM
tbl_borrow_logs
INNER JOIN tbl_select_item ON tbl_borrow_logs.log_id = tbl_select_item.logs_id
INNER JOIN tbl_machine ON tbl_machine.machine_id = tbl_select_item.machine
WHERE log_id = 2
AND concat(',',machine,',') LIKE concat('%,',machine_id,',%')
GROUP BY logs_id
SELECT
(SELECT GROUP_CONCAT(list ORDER BY list ASC SEPARATOR ', ') FROM tbl_machine m WHERE FIND_IN_SET(m.machine_id,tbl_select_item.machine) ) AS selected,
tbl_borrow_logs.`user`,
tbl_borrow_logs.fullname,
tbl_borrow_logs.log_id,
tbl_borrow_logs.depart,
tbl_select_item.amount,
tbl_borrow_logs.tel1,
tbl_borrow_logs.tel2,
tbl_borrow_logs.obj,
tbl_borrow_logs.logs_status,
tbl_borrow_logs.loan_by,
tbl_borrow_logs.approve_by,
tbl_borrow_logs.start_date,
tbl_borrow_logs.end_date,
tbl_borrow_logs.date_receive,
tbl_borrow_logs.date_return,
tbl_borrow_logs.place,
tbl_borrow_logs.signature_user,
tbl_borrow_logs.signature_admin,
tbl_borrow_logs.signature_super_admin,
tbl_borrow_logs.return_signature_user,
DATEDIFF(end_date,start_date) AS totalday,
DATE_FORMAT(start_date,'%d') AS thaidate,
DATE_FORMAT(start_date,'%Y')+543 AS thaiyear,
DATE_FORMAT(start_date,'%H.%i') AS thaitime,
DATE_FORMAT(end_date,'%d') AS thaidate2,
DATE_FORMAT(end_date,'%Y')+543 AS thaiyear2,
DATE_FORMAT(end_date,'%H.%i') AS thaitime2,
DATE_FORMAT(date_receive,'%d') AS thaidate3,
DATE_FORMAT(date_receive,'%Y')+543 AS thaiyear3,
DATE_FORMAT(date_receive,'%H.%i') AS thaitime3,
DATE_FORMAT(date_return,'%d') AS thaidate4,
DATE_FORMAT(date_return,'%Y')+543 AS thaiyear4,
DATE_FORMAT(date_return,'%H.%i') AS thaitime4
FROM
tbl_borrow_logs
INNER JOIN tbl_select_item ON tbl_borrow_logs.log_id = tbl_select_item.logs_id
WHERE log_id = 2
GROUP BY logs_id
SELECT GROUP_CONCAT(list ORDER BY list ASC SEPARATOR ', ') FROM tbl_machine m WHERE FIND_IN_SET(m.machine_id,GROUP_CONCAT(tbl_select_item.machine)) ) AS selected