Problem:
Ajax offers a search on [n] ingredients in recipes. That is: to compare recipes with several ingredients.
For example: SELECT Recipes using "flower", "salt" will create: "Pizza", "Bread", "Saltwater" , etc.
Tables:
Ingredients [ IngredientsID INT [PK], IngredientsName VARCHAR ] Recipes [ RecipesID INT [PK], RecipesName VARCHAR ] IngredientsRecipes [ IngredientsRecipesID INT [PK], IngredientsID INT, RecipesID INT ]
Query:
SELECT Recipes.RecipesID, Recipes.RecipesName, Ingredients.IngredientsID, Ingredients.IngredientsName FROM IngredientsRecipes INNER JOIN Ingredients ON IngredientsRecipes.IngredientsID = Ingredients.IngredientsID INNER JOIN Recipes ON IngredientsRecipes.RecipesID = Recipes.RecipesID WHERE Ingredients.IngredientsName IN ('salt', 'water', 'flower')
I am currently creating my request using ASP.NET C # due to the dynamic nature of the WHERE .
I bit that I need to build a query in my code layer instead of using a stored procedure / pure SQL, which theoretically should be much faster.
Do you have any thoughts on how I would move all the logic from my code layer to pure SQL, or at least how can I optimize the performance of what I'm doing?
I think of the lines of temporary tables:
Step One : SELECT IngredientsID FROM Ingredients and INSERT INTO temp-table
Step Two : SELECT RecipesName FROM Recipes connected to IngredientsRecipes connected to temp-table.IngredientsID
performance c # sql-server
roosteronacid Sep 27 '08 at 21:47 2008-09-27 21:47
source share