0
我一直在尝试这项要求几个小时,但即时通讯,因为我没有得到所需的结果。Mysql 2表连接限制结果返回从这两个表
我有两张桌子。
**Main Comment Table
----------------------------------------------------------------------------
id | comments | date_commented | comment_owner | commented_by
1 hello world ********** 321 123
Child Comment Table
----------------------------------------------------------------------------
id | mainpostID| child_comment_data | commented_by | date_commented**
1 1 child comment of hello world 456 ********
我的要求:
我想与Chilcomments沿着取得前10的主要评价每一个主要的意见。我希望将每条主评论的子评论数量限制为5个。
我的尝试:
SELECT maincomment.comments, childcomment.child_comment_data
FROM maincomment
LEFT JOIN childcomment ON maincomment.id = childcomment.mainpostID
AND maincomment.comment_owner = childcomment.commented_by
WHERE maincomment.id = childcomment.mainpostID
ORDER BY dateposted DESC
LIMIT 10
结果:IM只得到10 Maincomments但childcomments数量仅有1为每个主要的意见。我需要的是为每个Maincomment返回5个孩子评论。
有没有人请帮忙提出一些建议/在这里查询。
非常感谢。