T-SQL Tutorials - TSQLTutorials.com

INTERSECT - Common Between Sets


Introduction

The INTERSECT keyword in TSQL is used to find what is common between two datasets. The two datasets must have the same number of columns in them and use the same datatypes. The datasets must also have the columns in the same comparative order. The INTERSECT T-SQL Expression places the INTERSECT keyword between two datasets. By using the INTERSECT keyword between two datasets, TSQL will return a new dataset that just contains the common area between both datasets. The INTERSECT keyword is often used in this fashion:

  • SELECT col1,col2,coln... FROM table1 '[DataSet #1]
  • INTERSECT
  • SELECT col1,col2,coln... FROM table2 '[DataSet #2]

image of intersection of two datasets
The above image represents the use of INTERSECT between two datasets. The top circle (red) represents the first dataset, and the bottom circle (blue) represents the second dataset. The overlapping area (green) is the section that is common to both datasets. By using the INTERSECT keyword between two datasets (red & blue circles), TSQL will return a new dataset that just contains the common area between both datasets (Green Overlapping Area).


Microsoft SQL Server 2014 Standard Edition Server w/20 CAL’s

Price: $641.99
Buy It Now
MSFT SQL Server 2016 Standard Edition x64 64bit | Original | 10CAL | 24hour sale

Price: $399.99
Buy It Now
Microsoft SQL Server 2012 Standard Server +10CAL License Key Factory Sealed Pack

Price: $795
Buy It Now
Microsoft SQL Server 2016 Enterprise w/ 5 CAL | Full Retail Media |

Price: $653.99
Buy It Now
MSFT SQL Server 2008 R2 Standard Edition 32/x64 | Full | 10CAL, Media, License

Price: $299.99
Buy It Now
Lenovo Microsoft SQL Server 2014 - License - 1 User CAL - OEM

Price: $242.08
Buy It Now







Copyright 2017 - TSQLTutorials.com