What's different between INTERSECT and JOIN?
What's different between INTERSECT and JOIN?
1.INTERSECT just compares 2 sets and picks only distinct equivalent values from both sets.
It's important to note that NULL marks are considered as equals in INTERSECT set operator.
Also sets should contain equal number of columns with implicitly convertible types.
- Under Join i guess you mean INNER JOIN? INNER JOIN will return you rows where matching predicate will return TRUE. I.E. if there are NULL marks in both tables those rows will not be returned because NULL <> NULL in SQL.
Also INTERSECT is just comparing SETS on all attributes. Their types should be implicitly convertible to each other. While in join you can compare on any predicate and different types of sets. It is not mandatory to return just rows where there are matches. For example you can produce cartesian product in join.
Select * from Table1
Join Table2 on 1 = 1
https://www.quora.com/What-is-the-difference-between-inner-join-and-intersect
There are 3 differences
Intersect is an operator and Inner join is a type of join.
Intersect can return matching null values but inner join can't.
Intersect doesn't return any duplicate values but inner join returns duplicate values if it's present in the tables.
Try the following, for example:
CREATE TABLE a (id INT);
CREATE TABLE b (id INT);
INSERT INTO a VALUES (1), (NULL), (2);
INSERT INTO b VALUES (1), (NULL), (3), (1);
SELECT a.id
FROM
a INNER JOIN b
ON a.id
= b.id
;
output
1
1
SELECT id FROM a
INTERSECT
SELECT id FROM b;
Output
Null
1
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2019-06-01 530. Minimum Absolute Difference in BST
2019-06-01 501. Find Mode in Binary Search Tree
2018-06-01 Define class with itself as generic implementation. Why/how does this work?
2016-06-01 Task.ConfigureAwait
2015-06-01 新建并保存一个空的Excel
2015-06-01 创建了对嵌入的互操作程序集间接引用,无法嵌入互操作类型
2015-06-01 演练:Office 编程(C# 和 Visual Basic)