oracleunion用法
的有关信息介绍如下:
oracleunion用法
新建一个教师表包括以下字段与数据:
createtableteacher
(
idintprimarykey,
namenvarchar2(50)notnull,
scorenumbernotnull
);
insertintoteacher values(1,'Aaron',250);
insertintoteachervalues(2,'Bill',250);
insertintoteacher values(3,'Cindy',250);
insertintoteacher values(4,'Damon',260);
insertintoteachervalues(5,'Ella',260);
insertintoteachervalues(6,'Frado',260);
insertintoteachervalues(7,'Gill',260);
insertintoteachervalues(8,'Hellen',260);
insertintoteachervalues(9,'Ivan',260);
insertintoteachervalues(10,'Jay',260);
commit;
select*
fromteacher
whereid<4
union
select*
fromteacher
whereid>2andid<6
结果将是
1Aaron250
2Bill250
3Cindy250
4Damon260
5Ella260
union指令的目的是将两个 SQL 语句的结果合并起来,可以查看你要的查询结果。会排除重复的记录。
然而unionall 不会排除重复的记录。
看下面的示例:
如果换成UnionAll连接两个结果集
select*
fromteacher
whereid<4
unionall
select*
fromteacher
whereid>2andid<6
则返回结果是:
1Aaron250
2Bill250
3Cindy250
3Cindy250
4Damon260
5Ella260
通过对比,希望我们能清楚的认识这个union的用法。
如果对您有帮助,请点击下面的投票支持我,谢谢。



