Join table problems

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.