关于文章回复问题
我有个文章表 id 和内容 2个字段 然后回复也有2个字段 文章id 和回复内容 字段
怎么查询语句 渲染出以下html 我用leftjoin貌似不好使。。
文章内容回复内容
回复内容
回复讨论(解决方案) 贴出你的代码看看。
贴出你的代码看看。
你认为应该怎么写leftjoin后 然后怎么办? 建议你把你写的代码贴出来,人家可以在你的基础上改。
文章表 a id title content cid 回复表b cid content
select a.title,a.content,b.content from a left join b a.cid=b.cid
仅供参考 没考虑任何 需求和优化
你可以查询两次
1.查询文章id=1的明细
select * from article where id=1
2.查询文章article_id=1的回复
select *from comment where article_id=1
大概是这么个意思,供参考
select a.title,a.content,b.content from a left join b on a.cid=b.cid
看红色部分
你可以查询两次
1.查询文章id=1的明细
select * from article where id=1
2.查询文章article_id=1的回复
select *from comment where article_id=1
大概是这么个意思,供参考
我能不能不要2次 我这个要发给客户端呢 我用leftjoin后 怎么渲染呢
你可以查询两次
1.查询文章id=1的明细
select * from article where id=1
2.查询文章article_id=1的回复
select *from comment where article_id=1
大概是这么个意思,供参考
我能不能不要2次 我这个要发给客户端呢 我用leftjoin后 怎么渲染呢
这个2次查询效率高点,left join 完全没有必要,你不是还有php的么,在php变量里面拼接