Reputation: 75
I have two tables:
Table menu:
+-------------+--------------+
| id_calories | id_type_diet |
+-------------+--------------+
| 39 | 48 |
+-------------+--------------+
And table product_attribute:
+--------------+----------------------+
| id_attribute | id_product_attribute |
+--------------+----------------------+
| 39 | 93 |
+--------------+----------------------+
| 48 | 93 |
+--------------+----------------------+
Is it possible in MYSQL to get values of id_calories and id_type diet from table menu then check if both of these values exist in column id_attribute from table product_attribute and then get the value of id_product_attribute? In this example get id_product_attribute = 93?
Upvotes: 0
Views: 144
Reputation: 189
This should do the trick:
SELECT b1.id_product_attribute
FROM menu a
LEFT JOIN product_attribute b1 ON a.id_calories = b1.id_attribute
LEFT JOIN product_attribute b2 ON a.id_type_diet = b2.id_attribute
WHERE b1.id_product_attribute = b2.id_product_attribute
Upvotes: 1