Syntax:
SELECT <SELECTION_FIELDS> FROM <TABLES> <OPTIONAL_ADDITIONAL_QUERY CRITERIA> <INTERSECT OR EXCEPT> SELECT <SELECTION_FIELDS> FROM <TABLES> <OPTIONAL_ADDITIONAL_QUERY CRITERIA>
Notes:
The number of fields in the <SELECTION_FIELDS> must be the same. The datatypes of the fields in the <SELECTION_FIELDS> need to be compatible.
Examples:
--Intersect SELECT DISTINCT(CustomerID) FROM SALES.CustomerTransactions ct WHERE ct.TransactionDate BETWEEN '2016-01-01' AND '2016-12-31' --263 records returned by this query INTERSECT SELECT DISTINCT(CustomerID) FROM SALES.CustomerTransactions ct WHERE ct.TransactionDate BETWEEN '2013-01-01' AND '2013-12-31' --225 records returned by this query --result is 225 records
--Except
SELECT DISTINCT(CustomerID)
FROM SALES.CustomerTransactions ct
WHERE ct.TransactionDate BETWEEN '2016-01-01' AND '2016-12-31'
--263 records returned by this query
EXCEPT
SELECT DISTINCT(CustomerID)
FROM SALES.CustomerTransactions ct
WHERE ct.TransactionDate BETWEEN '2013-01-01' AND '2013-12-31'
--225 returned by this query Records
--result is 38 records