Home > Enterprise >  SQL join to narrow result set
SQL join to narrow result set

Time:03-20

Here is my issue: I have 2 tables: recipes and ingredients. If I search by 2 ingredients, I get too many rows. These are the tables:

SELECT 
  id, 
  recipe_name
FROM recipes
SELECT
   id,
   ingredient_name,
   recipe_id
FROM ingredients

Let's say I want to display all recipes that contain certain ingredients, for example "banana" and "applesauce". This is the query I wrote:

SELECT DISTINCT "recipes".* 
FROM "recipes" 
LEFT  JOIN "ingredients" ON 
"ingredients"."recipe_id" = "recipes"."id" 
WHERE (ingredient_name LIKE '           
  •  Tags:  
  • sql
  • Related