dimanche 12 avril 2015

Check multiple values in a select statement

Given a table with sales like this:



| PRODUCT_ID | USER_ID |
|------------|---------|
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
| 3 | 2 |
| 4 | 2 |
| 1 | 3 |
| 3 | 3 |


And a table with products and manufacturers like this:



| PRODUCT_ID | MANUFACTURER_ID |
|------------|-----------------|
| 1 | 1 |
| 2 | 1 |
| 3 | 2 |
| 4 | 2 |


How can I find the users that have bought all products from a manufacturer? I know I can use



SELECT *
FROM product
WHERE MANUFACTURER_ID = x


to find which products belong to a manufacturer x, but I don't have any idea as to how to continue from there.


Aucun commentaire:

Enregistrer un commentaire