MySQL查询篇-集合运算

文章目录

  • [union (并集)](#union (并集))
    • [union distinct](#union distinct)
    • [union all](#union all)
  • intersect(交集)
    • [intersect all](#intersect all)
    • [intersect distinct](#intersect distinct)
  • [except 差集](#except 差集)
    • [except distinct](#except distinct)
    • [except distinct](#except distinct)
    • [except all](#except all)

union (并集)

union distinct

使用前提:a和c数据类型一致,b和d数据类型一致,查询的两个结果集列数也得相同

默认的union 即为union distinct

复制代码
select a,b from table1
union
select c,d from table2;

union all

并集不去重

MySQL只支持union

intersect(交集)

intersect all

intersect distinct

except 差集

except distinct

except 差集

except distinct

except all

相关推荐
4***14901 小时前
MySQL调试技巧与工具
数据库·mysql
Arva .1 小时前
如何监控并优化慢 SQL?
数据库·sql
n***54381 小时前
【MySQL】MySQL内置函数--日期函数字符串函数数学函数其他相关函数
android·mysql·adb
linchare3 小时前
linux debian上只装mysql的客户端步骤
linux·mysql·debian
w***4244 小时前
【MySQL】复合查询
数据库·mysql
q***01774 小时前
【MySQL】表的基本操作
数据库·mysql·oracle
budingxiaomoli4 小时前
存储过程和触发器
数据库
q***12534 小时前
PostgreSQL_安装部署
数据库·postgresql
q***48255 小时前
mysql用户名怎么看
数据库·mysql
夏日玲子5 小时前
【Redis】Redis常用命令合集
数据库·redis·缓存