聯(lián)合結(jié)果集
新建臨時(shí)工數(shù)據(jù)表
復(fù)制代碼 代碼如下:
CREATE TABLE T_TempEmployee (FIdCardNumber VARCHAR(20),FName VARCHAR(20),FAge int,PRIMARY KEY(FIdCardNumber));
INSERT INTO T_TempEmployee(FIdCardNumber,FName,FAge) VALUES('1234567890121','Sarani',33);
INSERT INTO T_TempEmployee(FIdCardNumber,FName,FAge) VALUES('1234567890122','Tom',26);
INSERT INTO T_TempEmployee(FIdCardNumber,FName,FAge) VALUES('1234567890123','Yalaha',38);
INSERT INTO T_TempEmployee(FIdCardNumber,FName,FAge) VALUES('1234567890124','Tina',26);
INSERT INTO T_TempEmployee(FIdCardNumber,FName,FAge) VALUES('1234567890125','Konkaya',29);
INSERT INTO T_TempEmployee(FIdCardNumber,FName,FAge) VALUES('1234567890126','Fotifa',46);
Union聯(lián)合
復(fù)制代碼 代碼如下:
select FNumber,FAge from T_Employee
union
select FIdCardNumber,FAge from T_TempEmployee
union上下的查詢個(gè)數(shù)和類型必須對(duì)應(yīng)一致
復(fù)制代碼 代碼如下:
select FNumber,FAge,FDepartment from T_Employee
union
select FIdCardNumber,FAge ,'臨時(shí)工,無(wú)部門(mén)' from T_TempEmployee
union默認(rèn)將重復(fù)數(shù)據(jù)去掉。如果不讓他去掉,則用union all
復(fù)制代碼 代碼如下:
select FName from T_Employee
union all
select FName from T_TempEmployee