下面的 mysql 将返回我的数据库中的前 10 个帖子,以及与这 10 个帖子相关的评论,以及与帖子相关的用户,整个事情按帖子的标题排序。
SELECT * FROM
(SELECT * FROM posts LIMIT 0,10 ORDER BY posts.title) as post
LEFT JOIN comments AS comment ON comment.postId = post.id,
authors AS author
WHERE post.authorId = author.id
如何按 author.name 排序?将 posts.title 更改为 author.name 会给我一个错误:
Table 'comment' from one of the SELECTs cannot be used in global ORDER clause