T-SQL Tutorials - TSQLTutorials.com

EXCEPT - Difference Between Sets


Introduction

The EXCEPT keyword in TSQL is used to find what is different 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 EXCEPT T-SQL Expression places the EXCEPT keyword between two datasets. By using the EXCEPT keyword between two datasets, TSQL will return a new dataset that just contains what is in the first dataset and not in the second dataset. The EXCEPT keyword is often used in this fashion:

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

image of EXCEPT clause between two datasets
The above image represents the use of EXCEPT between two datasets. The top circle (red) represents the first dataset, and the bottom circle (blue) represents the second dataset. The overlapping area is the section that is common to both datasets. By using the EXCEPT keyword between two datasets (red & blue circles), TSQL will return a new dataset that just contains the records that are unique to the first dataset (red) and not contained in the second dataset (blue), or the overlapping area.


Microsoft SQL Server 2008 R2 Standard Server License key +5CAL FactorySealedPack

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

Price: $949
Buy It Now
Add-On Microsoft SQL Server 2008 R2 5CAL Standard Enterprise Datacenter Sealed!

Price: $199
Buy It Now
Brand New - Microsoft SQL Server 2014 Standard Edition SP2 and 25 CAL License

Price: $899
Buy It Now
Factory Sealed- 228-10602 Microsoft SQL Server 2016 Standard 10 CAL NEW!!

Price: $2169.99
Buy It Now
Microsoft SQL Server 2005 Standard IA64 5 CAL, Itanium System, New, PN 228-04025

Price: $899.95
Buy It Now







Copyright 2017 - TSQLTutorials.com