mysql三张表关联查询

三张表,需要得到的数据是标红色部分的。sql如下:

select a.uid,a.uname,a.upsw,a.urealname,a.utel,a.uremark, b.rid,b.rname,b.rremark,c.deptid,c.deptname,c.deptremark

from table1 a,table2 b,table3 c where a.sems_role_rid=b.rid and a.udeptid=c.deptid 

或者:

select a.uid,a.uname,a.upsw,a.urealname,a.utel,a.uremark, b.rid,b.rname,b.rremark,c.deptid,c.deptname,c.deptremark

from table1 a left join table2 b on  a.sems_role_rid=b.rid left join table3 c on a.udeptid=c.deptid 

LEFT JOIN 可以实现统一数据库多表联合查询符合条件的数据。 

原文地址:https://www.cnblogs.com/vanl/p/5472812.html