sql语句中union的用法

union联合的结果集不会有重复值,如果要有重复值,则使用union all

union会自动压缩多个结果集合中重复的结果,使结果不会有重复行,union all 会将所有的结果共全部显示出来,不管是不是重复。

union:会对两个结果集进行并集操作,不包括重复行,同时进行默认规则的排序。

union all:对两个结果集进行并集操作,包括重复行,不会对结果进行排序。

 

  employee_china表:

 

employee_usa表:

 

 union:

 

 去掉: 

 

  union all:

 

 不能去掉: 

 

 当存在不相同的字段时: (employees_china 增加一个字段 E_Hello)

 

  必须进行补充:

 

 

 

 原文:https://blog.csdn.net/weixin_42383680/article/details/119858753

 

posted @ 2022-11-19 12:41  sucre_tan  阅读(427)  评论(0编辑  收藏  举报