table structure ....Here is only 3 tables.. (bought ,customer,product). ..
bought table structure : fields (id,product_id,customer_id),
customer table struc
I want to get customers who bought product 'a' but did not buy products 'b'
Try this:
SELECT *
FROM Customers c
INNER JOIN
(
SELECT *
FROM bought
WHERE product_id = id of 'a'
) ba ON c.CustomerId = ba.CustomerId
LEFT JOIN
(
SELECT *
FROM bought
WHERE product_id = id of 'b'
) bb ON c.CustomerId = bb.CustomerId
WHERE bb.CustomerId IS NULL;