- Edited
I am trying to query a database and select customers who bought products A, B, but did NOT buy product C. So, even if they did buy products A, B but they also purchase C I want to exclude them from my list. I know I can do this w/ PHP but I am wondering if this is possible w/ SQL alone.
Here is what I have tried. I also tried something similar using EXCEPT. With the code below I am still getting the customer who ordered product "C"
SELECT m.hdcust, m.hditem
FROM files.histdtl AS m
WHERE m.hditem IN ('RICOH3300SET1', 'RICOH7700SET1', 'RICOH7700SET2', 'RICOH7000SET1', 'RICOH7100SET1', 'RICOH7100SET2', 'RICOHGXE3300N', 'RICOHGXE7700N', 'RICOHSG3110DN', 'RICOHSG7700DN')
AND m.hditem NOT IN (SELECT f.hditem
FROM files.histdtl AS f
WHERE f.hditem IN ('SG400', 'SG800', 'SG400SET1', 'SG800SET1', 'SG800SET2'))
ORDER BY m.hdcust ASC
Thanks
(Added [code]...[/code]
tags ~ MOD)