首页 > 数据库技术 > 详细

SQL——minus、union 、interspect

时间:2021-04-16 17:59:13      阅读:21      评论:0      收藏:0      [点我收藏+]

 

 

 

 

minus、union 、interspect

 

 

minus和not in的区别

minus可以寻找左边表存在右边表不存在的数据,即左边表减去两表的差集。

 

minus可以实现not in(使用not in注意空值)的所有功能,

例:

select * from sysdba.origin_table o where o. not in (select id from sysdba.destination_table);

(select id from SYSDBA.ORIGIN_TABLE ) minus (select id from SYSDBA.DESTINATION_TABLE);

但是多了一个功能即寻找所有字段的差集

(select * from SYSDBA.ORIGIN_TABLE ) minus (select * from SYSDBA.DESTINATION_TABLE);

假设有这两张表技术分享图片

技术分享图片

 

select * from sysdba.origin_table o where o.id not in (select id from sysdba.destination_table);

 

技术分享图片

多出来的功能:所有字段的比对:

(select * from SYSDBA.ORIGIN_TABLE ) minus (select * from SYSDBA.DESTINATION_TABLE);

技术分享图片

其实想想也容易明白,一个叫差集,偏重于集合即所有字段的数据,那么交集和in关键字也是一样的道理。

 

为什么不建议使用外键?

https://zhuanlan.zhihu.com/p/62020571

 

SQL——minus、union 、interspect

原文:https://www.cnblogs.com/EricShen/p/14666701.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!