• Thanks for article and comments - I learnt a lot.

    In MySQL 😀 this is the fastest by far:

    SELECT

    CustomerId

    FROM Purchase

    WHERE ProductCode IN ('A','B', 'C')

    GROUP BY CustomerID

    having sum(case when ProductCode = 'A' then 1 else 0 end) > 0

    and sum(case when ProductCode = 'B' then 1 else 0 end) > 0

    and sum(case when ProductCode = 'C' then 1 else 0 end) = 0

    Unfortunately MySQL does not have the EXCEPT operator.

    -jj