'Check if an option matches all the value in a list
I have two tables in MySQL, products and product_options. A product can have more than an option type.
Table product:
| id | name |
|---|---|
| 1 | Croissant |
| 2 | Croissant Medium |
| 3 | Coffee |
Table product_options:
| id | type | value | productId |
|---|---|---|---|
| 1 | weight | 40 | 1 |
| 2 | weight | 60 | 2 |
| 3 | weight | 6 | 3 |
| 4 | size | small | 3 |
As you can see, all the products have the option type weight set, while the option type size is set only for the product with id 3.
I'm trying to have a query only, that returns if a product option is set for all the products.
I'm expecting as result a mysqli object with a boolean for each product option type, to flag if the product option type is set for all the products.
In the example case should be:
| optionType | allProductsHaveIt |
|---|---|
| weight | true |
| size | false |
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
