• How about this? Although i agree query might get longer when there would be more than 3 items

    SELECT DISTINCT CustomerID

    FROM #Purchase P

    WHERE EXISTS (SELECT 1 FROM #Purchase P1

    WHERE P.customerid = P1.customerid

    AND P1.productcode = 'A'

    )

    AND EXISTS (SELECT 1 FROM #Purchase P2

    WHERE P.customerid = P2.customerid

    AND P2.productcode = 'B'

    )

    AND NOT EXISTS (SELECT 1 FROM #Purchase P3

    WHERE P.customerid = P3.customerid

    AND P3.productcode = 'C'

    )