나는 2 개의 테이블이있다- 요리 와 재료 :
에 요리, 나는 같은 주문 피자 요리의 목록을 가지고있다 :
에서 성분, 나는 같은 주문한 모든 요리에 대한 모든 다른 성분의 목록을 가지고있다 :
각 요리의 이름과 함께 각 요리의 모든 재료 이름을 모두 나열 할 수 있기를 원합니다 .
나는 성분 ID를 이름으로 바꾸지 않고 대신 빈 세트를 반환하도록 선택하는이 쿼리를 작성했습니다. 내가 뭘 잘못하고 있는지 설명해주세요.
SELECT dishes.name, ingredients.name, ingredients.id
FROM dishes
INNER JOIN ingredients
ON dishes.ingredient_1=ingredients.id,dishes.ingredient_2=ingredients.id,dishes.ingredient_3=ingredients.id,dishes.ingredient_4=ingredients.id,dishes.ingredient_5=ingredients.id,dishes.ingredient_6=ingredients.id, dishes.ingredient_7=ingredients.id,dishes.ingredient_8=ingredients.id;
다음을 참조 할 수 있다면 좋을 것입니다.
Disregard The Text In Hebrew - Treat It As Your Own Language.
1. The logic of the DB structuring - am I doing it correctly?
Pizza
PizzaIngredients
Ingredients
Pizza
would have ID
, name
, and type
where ID
is the primary key.
PizzaIngredients
것 PizzaId
및 IngredientId
(이 기본 키는 복합 키인 많은 많은 테이블 PizzaId
및 IngredientID
)는
Ingredients
가지고 ID
있고 기본 키는 name
어디에 ID
있습니다.
2. 각 요리의 이름과 함께 각 요리의 모든 재료 이름을 모두 나열합니다. MySQL
(unested) 에서 이와 같은 것 :
SELECT p.ID, p.name, GROUP_CONCAT(i.name) AS ingredients
FROM pizza p
INNER JOIN pizzaingredients pi ON p.ID = pi.PizzaID
INNER JOIN ingredients i ON pi.IngredientID = i.ID
GROUP BY p.id
3. 이전에 일대 다 관계가 필요한 문제를 경험 한 적이 있다면 PHP와 MySQL을 사용하여이 문제를 어떻게 해결 했습니까?
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다