SELECT d.*, l.name AS location_name, TRIM(CONCAT(e.last_name, ' ', e.first_name, ' ', e.patronymic)) AS employee_full_name, e.fk_id_department AS department_id, dep.name AS department_name FROM device d JOIN location l ON d.fk_id_location = l.id LEFT JOIN employee e ON d.fk_id_employee = e.id LEFT JOIN department dep ON e.fk_id_department = dep.id;