Related table questions about article Reply
I have an article table id and two fields in the content, and then there are two fields in the reply article id and reply content fields.
How to render the following html in the query statement? it seems difficult to use leftjoin ..
Article content
Reply content
Reply content
Reply to discussion (solution)
Paste your code.
Paste your code.
What do you think should be done after writing leftjoin?
We recommend that you paste the code you wrote so that people can modify it based on you.
Article table a id title content cid reply Table B cid content
Select a. title, a. content, B. content from a left join B a. cid = B. cid
For reference only, no requirements or Optimization considerations
You can query twice
1. query the details of the article id = 1
Select * from article where id = 1
2. query the reply of article article_id = 1
Select * from comment where article_id = 1
This is probably the reference.
Select a. title, a. content, B. content from a left join B on a. cid = B. cid
Check the red part
You can query twice
1. query the details of the article id = 1
Select * from article where id = 1
2. query the reply of article article_id = 1
Select * from comment where article_id = 1
This is probably the reference.
Can I send it to the client twice? how can I render it after I use leftjoin?
You can query twice
1. query the details of the article id = 1
Select * from article where id = 1
2. query the reply of article article_id = 1
Select * from comment where article_id = 1
This is probably the reference.
Can I send it to the client twice? how can I render it after I use leftjoin?
This two queries are highly efficient, and left join is completely unnecessary. Aren't you still using php? splice them in the php variable.