milani_lucie
asked on
Customers who purchased products (1 or 2 or 3) but not (4 or 5) - SQL Server
Hi,
I have CustProd table having Customers with Products information. Can you please provide me the SQL query for:
Customers who purchased products (1 or 2 or 3) but not (4 or 5)
Please note that customers may purchase Product "1" and Product "4" or Product "5". We want customers who purchased ONLY 1 or 2 or 3 but not "4" or "5".
Thanks
I have CustProd table having Customers with Products information. Can you please provide me the SQL query for:
Customers who purchased products (1 or 2 or 3) but not (4 or 5)
Please note that customers may purchase Product "1" and Product "4" or Product "5". We want customers who purchased ONLY 1 or 2 or 3 but not "4" or "5".
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@murphey
When first line is true, second always is true, they must come from differet records
When first line is true, second always is true, they must come from differet records
where ProdId in (1,2,3)
and ProdId not in (4,5)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
If CustProd is a part of the selection on a Customer table
Open in new window