多表联查
A表:id,createagentid,createtime,verifagentid,verifytime,status
B表:id,pid,sid,
C表:pid,pname,
D表:sid,sname,
E表:agentid,agentname
A.id=B.id
a.creteagentid=E.agentid
a.verifyagentid=E.agentid
B.pid=C.pid
B.sid=D.sid
其中A为主表,A.id在B中会有多个.B.pid,sid在C,D中只有一个.
查询条件为C.pname,D.sname,
显示数据为:A.*,不重复
我试过inner join,left join ,right join等连接.写不出来了...
------解决方案--------------------SELECT * FROM A
INNER JOIN B ON A.id = B.id
LEFT JOIN C ON B.pid = C.pid
LEFT JOIN D ON B.sid = D.sid
LEFT JOIN E AS E1 ON a.creteagentid = E1.agentid
LEFT JOIN E AS E2 ON a.verifyagentid = E2.agentid