Top 5 comments from a specific post. How to write my SQL
I want to show only the top 5 comments for a specific post (Like the post on facebook where people cant comment them).
gbn was kind enough to help figure out that issue by doing the following:
select * FROM tblPost P OUTER APPLY (SELECT TOP 5 * FROM tblComment C WHERE P.id = C.postid ORDER BY something) inline
But since I'm no sql grand master I would need your help to put that into my real sql statement.
SELECT * FROM memberactions INNER JOIN actions ON memberactions.actionid = actions.id INNER JOIN members ON memberactions.memberid = members.id LEFT OUTER JOIN members members_2 INNER JOIN actioncomments ON members_2.id = actioncomments.memberid INNER JOIN comments ON actioncomments.commentid = comments.id ON actions.id = actioncomments.actionid
So my question is could you rearrange my sql to put the OUTER APPLY in my real sql statement.
Assuming that my table comments reprensent tblComment and that actioncomments represent the table tblPost
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
There does not seem to be a need for the member_2 table at all, but this is a faithful representation of what you had (preserving member_2)
still don't know what you want to order by