为什么返回 23 行(正确的数量):
select users.user_id, users.fname, users.lname,
stars.stars, comments.comment from users
LEFT JOIN stars on users.user_id = stars.userid
JOIN comments on users.user_id = comments.sender
where users.user_id = ? order by comments.time desc;
这会返回 1 行?:
select users.user_id, users.fname, users.lname,
stars.stars, count(distinct comments.id) as amount,
comments.comment from users
LEFT JOIN stars on users.user_id = stars.userid
JOIN comments on users.user_id = comments.sender
where users.user_id = ? order by comments.time desc;
干杯。
最佳答案
需要对主数据进行分组或者对字段进行子查询。
关于php - 为什么将 count() 添加到我的 sql 查询中会使其无法工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9985847/