INTERSECT 交集集合运算,把集合共同拥有的记录返回来。
为了演示,首选创建两个变量表,并插入数据:
第一个表:
INSERT INTO @T1 VALUES ('tc1','tc2');
INSERT INTO @T1 VALUES ('tc3','tc4');
INSERT INTO @T1 VALUES ('tc5','tc6');
INSERT INTO @T1 VALUES ('tc13','tc14');
第二表:
INSERT INTO @T2 VALUES ('tc1','tc2');
INSERT INTO @T2 VALUES ('tc3','tc4');
INSERT INTO @T2 VALUES ('tc9','tc10');
INSERT INTO @T2 VALUES ('tc7','tc8');
INTERSECT交集运算:
INTERSECT
SELECT * FROM @T2
结果,