[英]How Do I JOIN a third Table called all_recipes using recipe_id KEY
SELECT COU.recipe_id, IFNULL(FOU.Found, 0) AS Found, COU.Count
FROM ( SELECT recipe_id, COUNT(recipe_id) As Count
FROM recipe_ingredients
GROUP BY recipe_id) COU
LEFT OUTER JOIN ( SELECT R.recipe_id, COUNT(R.key_ingredient) AS Found
FROM users_ingredients U
JOIN recipe_ingredients R ON R.key_ingredient = U.key_ingredient
GROUP BY R.recipe_id) FOU ON FOU.recipe_id = COU.recipe_id
我需要將三張桌子連接在一起 - 好吧,最后是 4 張。 有人可以告訴我如何做到這一點,並解釋如何在以后需要時繼續加入。 我將有 4 張或更多桌子。 非常感謝
以上歸功於@Arulkumar
我不太明白你的 SQL 是做什么的,但是要加入另一個表,你需要做這樣的事情。
SELECT recipe.id, all_recipes.id
FROM recipe
LEFT JOIN all_recipes ON recipe.id = all_recipes.id
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.