intersect & union | union all & minus

本文详细介绍了SQL中的交集(INTERSECT)、并集(UNION UNIONALL)和差集(MINUS)操作。INTERSECT用于找出两个查询结果的共同部分,同时处理NULL值;UNION和UNION ALL的区别在于是否去除重复行,UNION ALL保留所有记录而不去重;MINUS则返回第一表中但不在第二表中的记录。了解这些操作对于数据库查询和数据处理至关重要。

区别

intersect 交集 去重 排序
union 并集 去重 排序
union all 并集 不去重 不排序
minus 差集 前表中有,后表中没有的差集

intersect

It processes NULLs in the selected columns.

union | union all

The number of columns selected in each SELECT statement must be identical.

NULLS are not ignored during duplicate checking.

The data type group of each column returned by the second query must match the data type of the corresponding column returned by the first query.

The number, but not names, of columns must be identical for all SELECT statements in the query.

minus

SALES2 is a table with the same description as SALES1. Some sales data is duplicated in both tables.You want to display the rows from the SALES1 table which are not present in the SALES2 table.

学习链接

集合函数
交集(INTERSECT)、并集(UNION UNION ALL )、差集(MINUS)

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值