1

I have three tables:

Customer table

enter image description here

Product Table

enter image description here

Customer_Product Table

enter image description here

I need to make query: Search for customers who bought a certain product (for example, name = "toilet paper") at least 2 times I don't understand how.. I'm noob in databases.. Please help

1 Answer 1

1

You need aggregation :

select c.name
from customer c inner join
     customer_product cp
     on cp.customer_id = c.customer_id inner join
     product p
     on p.product_id = cp.product_id
where p.lable = 'toilet paper'
group by c.name
having count(p.lable) > 1;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.