• Just piping in on a something I just noticed in playing with INTERSECTand EXCEPT.  I expected that they would act identicle to EXISTS and NOT EXISTS but they don't.  They treat nulls differently.

    Based on the author's example create a quick reference table.

    SELECT

    TOP 1000 CustomerID, OrderDate, SalesPersonID

    INTO

    Sales.SalesOrderHeaderIntersection

    FROM

    Sales.SalesOrderHeader

    I expected the following two queries to return the same results.

    SELECT

    CustomerID, OrderDate, SalesPersonID FROM Sales.SalesOrderHeader INTERSECT

    SELECT

    CustomerID, OrderDate, SalesPersonID FROM Sales.SalesOrderHeaderIntersection

     

    SELECT

    CustomerID, OrderDate, SalesPersonID FROM Sales.SalesOrderHeader t1

    WHERE

    EXISTS

    (

    SELECT * FROM Sales.SalesOrderHeaderIntersection t2 WHERE t1.CustomerID=t2.CustomerID

    AND t1.OrderDate=t2.OrderDate AND t1.SalesPersonID=t2.SalesPersonID)

    They do not because [NOT] EXISTS ommitts the nulls as a non match while INTERSECT includes them