select `tbl_users`.`username`, `tbl_users`.`users_id`, `tbl_users`.`profile_picture`,
(select count(users_id) from tbl_movies_comments where users_id = `tbl_users`.`users_id`) as UsersCommentsCount,
(select count(users_id) from tbl_movies_reviews where users_id = `tbl_users`.`users_id`) as UserReviewsCount
left join `tbl_movies_comments` on `tbl_users`.`users_id` = `tbl_movies_comments`.`users_id`
left join `tbl_movies_reviews` on `tbl_users`.`users_id` = `tbl_movies_reviews`.`users_id`
group by `tbl_users`.`username`, `tbl_users`.`users_id`, `tbl_users`.`profile_picture`, `tbl_movies_comments`.`users_id`, `tbl_movies_reviews`.`users_id`
答案 0 :(得分:1)
你的陈述格式很糟糕。这就是为什么难以调试代码的一个原因......
....
(
SELECT
Count(users_id)
FROM
tbl_movies_reviews
WHERE
users_id = tbl_users.users_id
) AS userreviewscount
FROM yourtablename <<<--- Missing
left JOIN tbl_movies_comments
ON tbl_users.users_id = tbl_movies_comments.users_id
....
使用HeidiSQL或在线语法格式化程序/检查程序等工具来避免此类情况
答案 1 :(得分:0)
您的查询中没有FROM子句。
SELECT ...
FROM `tbl_users`
LEFT JOIN ...