I have the following columns from 2 tables with customers’ allergens and food recipes. I want to cross-check both columns to see which customers asked for recipes containing their allergens.
I cannot quite figure how to do it. The following code isn’t working for me, it reflects no findings, as if there was no match of values between both columns. Could anyone lend me a hand? Thanks!
enter image description here
This is what I tried:
SELECT customer.allergens, recipe.ingredients
FROM recipe
JOIN orders
ON recipe.id = orders.recipe_id
JOIN customer
ON orders.customer_id = customer.id
WHERE customer.allergens LIKE recipe.ingredients
Also a bit more rudimentary but still doesn’t yield good results.
SELECT customer.allergens, recipe.ingredients
FROM recipe
JOIN orders
ON recipe.id = orders.recipe_id
JOIN customer
ON orders.customer_id = customer.id
WHERE recipe.ingredients LIKE '%fish%' OR
recipe.ingredients LIKE '%pork%' OR
recipe.ingredients LIKE '%mayo%' OR
recipe.ingredients LIKE '%almonds%'
I was expecting to see a match, so if “almond” is in both columns, this is reflected in the querry.
alexalra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.