SQL EXCEPT and INTERSECT

-- AdventureWorks DB
SELECT ProductID   
FROM Production.Product  
INTERSECT  
SELECT ProductID   
FROM Production.WorkOrder ;
==== Gives ONLY matching ProductIDs..
SELECT ProductID   
FROM Production.Product  
EXCEPT  
SELECT ProductID   
FROM Production.WorkOrder ;  
--Result: 266 Rows (products without work orders)
==== Gives ProductIDs from Left Set which are NOT in the right Set.
Leave a Reply

Your email address will not be published. Required fields are marked *