Home > Database > Mysql Tutorial > SQL学习笔记六 union联合结果集使用

SQL学习笔记六 union联合结果集使用

WBOY
Release: 2016-06-07 18:02:15
Original
963 people have browsed it

SQL学习笔记六 union联合结果集使用,需要的朋友可以参考下。

联合结果集
新建临时工数据表
代码如下:
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
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template