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 Standard 2008 R2 10CAL 228-09180

Price: $2040
Buy It Now
SQL Server 2008 2005 Training Exam Test Developer DVD Enterprise Book mcts 5cal

Current Price: $16.99
Current Bids: 0
★ NEW ★ MS SQL 2005 Server Standard with CAL ★ L@@K PRICE REDUCTION★

Price: $395
Buy It Now
Microsoft SQL Server 2008 - Enterprise with 25 CAL's

Price: $13850
Buy It Now
228-04023 Microsoft SQL Server 2005 Standard 5 CAL

Price: $1450
Buy It Now
Microsoft SQL Server 2005 Workgroup Edition 5 CAL, New Retail, PN A5K-01017

Price: $699.95
Buy It Now







Copyright 2012 - TSQLTutorials.com