获取帖子列表的最新 3 条评论
目前,我正在运行一个查询来获取某个用户的所有帖子,然后在循环中,我正在查询该特定帖子的最新 3 条评论。效率超级低;我对每个帖子都一遍又一遍地查询。
我想合并我的查询,以便我对所有帖子只查询一次,对这些特定帖子的所有评论只查询一次。目前我有一个逗号分隔的列表,是我为该用户的所有帖子创建的(例如“1,5,18,9”)
posts
表:
posts
.idposts
.userid
comments
表:
comments
.idcomments
.relid (这是 postid)comments
.userid
查询应该使用我拥有的 $posts_list,这是以逗号分隔的帖子列表。或者对该用户的所有帖子进行子选择,但这似乎效率低下,因为我已经在字符串中包含了帖子列表。
非常感谢您的帮助!
Currently I'm running one query to get all posts for a user, then in the loop for that, I am querying for the latest 3 comments for that particular post. Super inefficient; I'm querying over and over again for every post.
I would like to consolidate my queries so that I query just once for all posts, and just once for all comments for those particular posts. At the moment I have a comma-separated list that I made for all posts for this user (e.g. "1,5,18,9")
posts
table:
posts
.idposts
.userid
comments
table:
comments
.idcomments
.relid (this is the postid)comments
.userid
The query should use the $posts_list I have, which is the comma-separated list of posts. Or a subselect for all posts for this user, but that seems inefficient since I already have the post list in a string.
Thanks so much for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这个查询 -
并添加您需要的条件,即 - WHERE p.userid IN (1,5,18,9)。
Try this query -
And add condition you need, i.e. - WHERE p.userid IN (1,5,18,9).