mysql三張表關聯查詢


參考網址: https://www.cnblogs.com/vanl/p/5472812.html

三張表,需要得到的數據是標紅色部分的。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 可以實現統一數據庫多表聯合查詢符合條件的數據。 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM