What's different between INTERSECT and JOIN?

后端 未结 1 1412
北恋
北恋 2021-01-13 00:36

Help me please.

Create data :

CREATE TABLE sub1(id int,name nvarchar(7));
CREATE TABLE sub2(id int,name nvarchar(7));
INSERT INTO sub1 VALUES(1,\'one1\         


        
相关标签:
1条回答
  • 2021-01-13 00:55
    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.

    enter image description here

    1. 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
    
    0 讨论(0)
提交回复
热议问题