2
列表查询+n 条附属结果,请教怎么查询比较优化
source link: https://www.v2ex.com/t/803388
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
article
文章表
comment
评论表
现查询文章列表 , 要求查询 10 篇文章,每篇文章附上最新的 3 条评论.
我现在的做法是查询出 10 篇文章.然后在代码里循环查询每篇文章的最新 3 条评论.
总计 1+10 次查询....
请教有什么更好的办法,减少查询次数吗?
子查询?或者再 mysql 中做函数 /存储过程?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK