UNION ALL \UNION

(一)UNION ALL \UNION 的用法和区别

  UNION UNION    ALL
用途   用于使用SELECT语句组合两个或多个表的结果集。 用于使用SELECT语句组合两个或多个表的结果集。
区别 结果不包含重复行 结果包含重复行
注意     每段select语句返回的列必须具有相同或可转换的数据类型,大小和相同的顺序。 同左



 

 

 

  

 

 

 

 

(二)

a.union all

SELECT '1' code, '新建' name FROM dual
UNION all
SELECT '2' code, '处理中' name FROM dual
UNION all
SELECT '3' code, '关闭' name FROM dual
union all
select '3' code,'关闭' name from dual

 

b.union

SELECT '1' code, '新建' name FROM dual
UNION
SELECT '2' code, '处理中' name FROM dual
UNION
SELECT '3' code, '关闭' name FROM dual
union
select '3' code,'关闭' name from dual

 

 (三) 业务需要

a.用于使用SELECT语句组合两个或多个表的结果集。

b.用于将可读性不强的字段值变成可读性较强的字段值

 

posted @ 2019-09-24 15:21  是不是唐辛子啊  阅读(208)  评论(0编辑  收藏  举报