执行sql语句:select '1' union select '3' union select '2'  union select '1'

得到的结果集如下:

union和union all比较说明

执行sql语句如下:

select '1' union all select '3' union all select '2' union all select '1'

union和union all比较说明

总结:

union是将多个结果集拼合到一起,如果存在相同的数据则只显示一条。同时会对结果集进行排序
union all是将多个结果集拼合到一起,如果存在相同的数据则都显示。union all的先后顺序就是结果集的顺序

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-30
  • 2022-12-23
  • 2021-05-24
  • 2021-07-23
猜你喜欢
  • 2021-05-14
  • 2022-02-12
  • 2022-01-30
  • 2022-12-23
  • 2022-02-10
  • 2022-02-26
相关资源
相似解决方案