Home > Backend Development > PHP Tutorial > sql关联问题ABC三个表,

sql关联问题ABC三个表,

WBOY
Release: 2016-06-23 13:45:40
Original
1205 people have browsed it

sql关联问题A\B\C三个表,A.id = B.aid   和A.id= C.a2id,这种关联如何写?


回复讨论(解决方案)

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

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



上一个写错了


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



上一个写错了


那怎样去A表和B表和C表里的值呢?万一有一样的,name字段



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



上一个写错了


那怎样去A表和B表和C表里的值呢?万一有一样的,name字段




你可以指定别名啊 例如

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
Copy after login
Copy after login
Copy after login




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



上一个写错了


那怎样去A表和B表和C表里的值呢?万一有一样的,name字段




你可以指定别名啊 例如

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
Copy after login
Copy after login
Copy after login






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



上一个写错了


那怎样去A表和B表和C表里的值呢?万一有一样的,name字段




你可以指定别名啊 例如

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
Copy after login
Copy after login
Copy after login


用thinkphp的关联形式$user->join("A on B.aid=A.id")这种形式,怎么写这种关联?

这个建议你看一下:http://doc.thinkphp.cn/manual/continuous_operation.html

这个建议你看一下:http://doc.thinkphp.cn/manual/continuous_operation.html


我现在很急,根本没时间看了,你跟我说说吧,谢谢了

$user = M('A');
$user->join("left join B on A.id=B.Id left join C on c.id=b.id")->field("A.id as aid,B,id as bid,……")->select(); 

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template