Home  >  Article  >  Backend Development  >  关联表有关问题

关联表有关问题

WBOY
WBOYOriginal
2016-06-13 11:57:22838browse

关联表问题
关于文章回复问题
我有个文章表  id 和内容 2个字段      然后回复也有2个字段 文章id 和回复内容 字段
怎么查询语句 渲染出以下html 我用leftjoin貌似不好使。。

文章内容

回复内容

回复内容


------解决方案--------------------
引用:
Quote: 引用:

你可以查询两次


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变量里面拼接
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn