G
Guest
Apologize for the long posting
I have a table where I track products purchased by customers. I have a query to retrieve customers who have purchased at least 3 specific products (passed as parameter). I use EXISTS, but this brings back all customers who have at least one of the products (works like an IN clause
This is the table (sample)
CUSTOMER_ID PRODUCT_I
1 100
1 110
1 130
1 140
2 100
2 110
2 140
This is the Query
select * from test7
where (((product_id = (100
or product_id = (110)
or product_id = 130)) an
exists (select product_id from test7 b
where a.user_id = b.user_id
and product_id = 100
and exists (select product_id from test7 b
where a.user_id = b.user_id
and product_id = 110
and exists (select product_id from test7 b
where a.user_id = b.user_id
and product_id = 130)
Any help would be greatly appreciated
Thanks
R
I have a table where I track products purchased by customers. I have a query to retrieve customers who have purchased at least 3 specific products (passed as parameter). I use EXISTS, but this brings back all customers who have at least one of the products (works like an IN clause
This is the table (sample)
CUSTOMER_ID PRODUCT_I
1 100
1 110
1 130
1 140
2 100
2 110
2 140
This is the Query
select * from test7
where (((product_id = (100
or product_id = (110)
or product_id = 130)) an
exists (select product_id from test7 b
where a.user_id = b.user_id
and product_id = 100
and exists (select product_id from test7 b
where a.user_id = b.user_id
and product_id = 110
and exists (select product_id from test7 b
where a.user_id = b.user_id
and product_id = 130)
Any help would be greatly appreciated
Thanks
R