SQL Association issues ABC three tables,

Source: Internet
Author: User
SQL association question ABC three tables, SQL association question A \ B \ C three tables,. id = B. aid and. id = C. a2id. how do I write this association?


Reply to discussion (solution)

select A.*,B.*,C.* from Aleft join B on A.id = B.aidleft join C on A.id = B. a2id

select A.*,B.*,C.* from Aleft join B on A.id = B.aidleft join C on A.id = C.a2id



The previous one was wrong.


select A.*,B.*,C.* from Aleft join B on A.id = B.aidleft join C on A.id = C.a2id



The previous one was wrong.


So how do we get the values in Table A and Table B and Table C? In case of the same name field



select A.*,B.*,C.* from Aleft join B on A.id = B.aidleft join C on A.id = C.a2id



The previous one was wrong.


So how do we get the values in Table A and Table B and Table C? In case of the same name field




You can specify an alias. for example:

select A.name as aname,B.name as bname,C.name as cname from Aleft join B on A.id = B.aidleft join C on A.id = C.a2id




select A.*,B.*,C.* from Aleft join B on A.id = B.aidleft join C on A.id = C.a2id



The previous one was wrong.


So how do we get the values in Table A and Table B and Table C? In case of the same name field




You can specify an alias. for example:

select A.name as aname,B.name as bname,C.name as cname from Aleft join B on A.id = B.aidleft join C on A.id = C.a2id






select A.*,B.*,C.* from Aleft join B on A.id = B.aidleft join C on A.id = C.a2id



The previous one was wrong.


So how do we get the values in Table A and Table B and Table C? In case of the same name field




You can specify an alias. for example:

select A.name as aname,B.name as bname,C.name as cname from Aleft join B on A.id = B.aidleft join C on A.id = C.a2id


How can I write this association in the form of join ("A on B. aid = A. id") of $ user-> join ("A on B. aid = A. id") in thinkphp?

Let's take a look at this: http://doc.thinkphp1.cn/manual/continuous_operation.html

Let's take a look at this: http://doc.thinkphp1.cn/manual/continuous_operation.html


I am in a hurry. I have no time to read it. please tell me. thank you.

$ User = M ('A ');
$ User-> join ("left join B on. id = B. id left join C on c. id = B. id ")-> field (". id as aid, B, id as bid ,...... ")-> Select ();

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.