联合结果集
新建临时工数据表
复制代码 代码如下:
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联合
复制代码 代码如下:
select fnumber,fage from t_employee
union
select fidcardnumber,fage from t_tempemployee
union上下的查询个数和类型必须对应一致
复制代码 代码如下:
select fnumber,fage,fdepartment from t_employee
union
select fidcardnumber,fage ,’临时工,无部门’ from t_tempemployee
union默认将重复数据去掉。如果不让他去掉,则用union all
复制代码 代码如下:
select fname from t_employee
union all
select fname from t_tempemployee