select x.*, y.*, z.* from x as xx
left join y as yy on xx.cate = yy.scid
left join z as zz on zz.cate = zz.scid
我不是很明白你说的三个表的区域之间的关联,这个可能有错你可以改改
如果两个表相同名称的字段相关联的话条件就是aa.name = bb.name
1、创建三张测试表;
createtabletest_a(aidint,anamevarchar(20))
createtabletest_b(bidint,bnamevarchar(20))
createtabletest_c(aidint,bidint,valuevarchar(20))
2、三张表中分别插入数据;
insertintotest_avalues(1,'aname1')
insertintotest_bvalues(2,'bname1')
insertintotest_cvalues(1,2,'cvalue')
3、查询表中记录;
select10,a.*fromtest_aa
unionall
select20,b.*fromtest_bb
unionall
select*fromtest_cc
4、编写sql,进行三表关联;
selecta.aname,b.bname,c.value
fromtest_ccjointest_aa
onc.aid=a.aid
jointest_bb
onc.bid=b.bid
---table1指的是第一张表,table2指的是第二张表,table3指的是第三张表,select a.uid,a.uname,a.upsw,a.urealname,a.utel,a.remark,b.rname,b.rremark,c.deptname,c.deptremark from table1 a,table2 b, table3 c where a.sems_role_rid=b.rid and a.udeptid=c.deptid
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)