--人员信息表 create table tbStaff ( id nvarchar(36) primary key default newid() not null, staffName nvarchar(36) , staffCNname nvarchar(36) , staffENname nvarchar(36) , staffNo nvarchar(36) , Companyname nvarchar(36) ) --公司信息表 create table tbCompany ( id nvarchar(36) primary key default newid() not null, Companyname nvarchar(36) , Companycode nvarchar(36) , Companyremark nvarchar(36) ) insert into tbStaff(staffName,staffCNname,staffENname,staffNo,Companyname) values('江威','江威','jiangwei','pcitjwe','集团公司') insert into tbStaff(staffName,staffCNname,staffENname,staffNo,Companyname) values('赵智勇','赵智勇','zhaozhiyong','pcitzzy','集团公司') insert into tbStaff(staffName,staffCNname,staffENname,staffNo,Companyname) values('华峰','华峰','huafeng','pcithue','集团公司') insert into tbStaff(staffName,staffCNname,staffENname,staffNo,Companyname) values('华峰','华峰','huafeng','pcithue','总公司') insert into tbCompany(Companyname,Companycode,Companyremark) values('集团公司','JTGS','集团公司备注') insert into tbCompany(Companyname,Companycode,Companyremark) values('工程公司','GCGS','工程公司备注') insert into tbCompany(Companyname,Companycode,Companyremark) values('运营公司','YYGS','运营公司备注')
1 准备如上脚本,两表的数据见如图:
---------------------------------------------------
2 join / inner join
----------------------------------------
3 right join
-------------------------------------------
4 left join