Intersection, _mssql2005, and difference set operations for SQL Server data sets

Source: Internet
Author: User
Their corresponding relationship can refer to the following diagram of the relevant test examples are as follows:

The relevant test examples are as follows:
Copy Code code as follows:

Use tempdb
Go
if (object_id (' T1 ') is not null) drop table T1
if (object_id (' T2 ') is not null) drop table t2
Go
CREATE TABLE T1 (a int)
INSERT INTO T1 SELECT 1 Union SELECT 2 Union Select 3
CREATE TABLE t2 (a int)
INSERT INTO T2 Select 3 Union Select 4 Union Select 5
Go
SELECT * FROM t1 union SELECT * T2
Go
/* Find table and set
1
2
3
4
5*/
SELECT * FROM t1 UNION ALL select * FROM T2
Go
/* Find table and set does not filter duplicate
1
2
3
3
4
5*/
SELECT * FROM t1 except select * FROM T2
Go
/* To find the difference set of T1 to T2
1
2*/
SELECT * FROM t1 intersect select * FROM T2
Go
/* Find the intersection of T1 to T2
3*/
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.