子查询返回超过1行?闷闷不乐?
SELECT `t_files`.*, `t_users`.`username`,
(SELECT CONCAT(b.first_name, " ", b.last_name)
FROM t_files AS a
JOIN t_users as b
ON b.id = a.user_id
) as upload_by
FROM `t_files`
LEFT JOIN `t_files_permission`
ON `t_files_permission`.`id_files` = `t_files`.`file_id`
LEFT JOIN `t_users`
ON `t_users`.`id` = `t_files_permission`.`id_users`
WHERE `t_files`.`company_id` = '1'
AND `t_files_permission`.`id_users` = '59'
AND `is_deleted` =0

答案 0 :(得分:0)
SELECT t_files
。*,t_users
。username
,
(SELECT CONCAT(b.first_name,"",b.last_name)
FROM t_files AS a
JOIN t_users AS b ON b.id = a.user_id
在哪里a.id_users` =' 59'
)作为upload_by
来自t_files
LEFT JOIN t_files_permission
点击t_files_permission
。id_files
= t_files
。file_id
LEFT JOIN t_users
点击t_users
。id
= t_files_permission
。id_users
在t_files
。company_id
=' 1'和t_files_permission
。id_users
=' 59' AND is_deleted
= 0
答案 1 :(得分:0)
试试这种方式
SELECT `t_files`.*, `t_users`.`username`,
(select CONCAT(b.first_name, " ", b.last_name)
from t_files as a
join t_users as b on b.id = a.user_id
where t.files.id=a.id) as upload_by
FROM `t_files` as
LEFT JOIN `t_files_permission` ON `t_files_permission`.`id_files` = `t_files`.`file_id`
LEFT JOIN `t_users` ON `t_users`.`id` = `t_files_permission`.`id_users`
WHERE `t_files`.`company_id` = '1' AND `t_files_permission`.`id_users` = '59' AND `is_deleted` =0
我认为你不需要子查询。您可以使用联接来解决问题。