0
我想查詢結果集到一個變量,然後使用該結果的另一個查詢循環。通過mysql的臨時表
所以現在我有幾個類型的威士忌在我的成分表,我能找到的所有的人,並用:
CREATE TEMPORARY TABLE TempTable (Ingredient_Id int);
Insert into TempTable Select Ingredient_Id from ingredients where INSTR(Ingredient_Name,'Whiskey')>0;
這給了我所有我的ID,我需要。然後,我想獲得有關數據:
select drink_names.*,ingredients.*, drink_recipes.*
from drink_recipes
Left JOIN drink_names ON drink_recipes.Drink_Id = drink_names.Drink_Id
Left JOIN ingredients ON ingredients.Ingredient_Id = drink_recipes.Ingredient_Id
where drink_recipes.Ingredient_Id in TempTable #This is the problem
Order By Drink_Name
我在如何與每個ID在TempTable
不錯!謝謝。甚至不需要臨時表。 – Nick