Sample Header Ad - 728x90

Make a query where the colums are based on finding text from another table

0 votes
1 answer
164 views
This is probably easier to explain with a toy example. I have a MSSQL database with two tables. Firstly, I have table A, which has two columns: "Dish_name" and "Dish_ingredients". It looks something like this: | Dish_name | Dish_ingredients| | -------- | ------------ | | Strawberry cheesecake | Butter, wheat, cream cheese, sugar, blueberry jam | | Beef stew | Beef, tomatoes, carrots, celery, canola oil, onions | | Spaghetti carbonara | Pasta, eggs, heavy cream, pork belly, salt | | Avocado toast | Toast, avocado | | ... | ... | The second table, Table B, lists all the ingredients I may find and whetehr they are dairy products, have gluten, etc. |Ingredient|Is_dairy|Has_gluten| |----------|--------|----------| |Butter|1|0| |Wheat|0|1| |Cream cheese|1|0| |Sugar|0|0| |Blueberry jam|0|0| |Beef|0|0| |Tomatoes|0|0| |Carrots|0|0| |Celery|0|0| |Canola oil|0|0| |Onions|0|0| |Pasta|0|1| |Eggs|0|0| |Heavy cream|1|0| |Pork belly|0|0| |Salt|0|0| |Toast|0|1| |Avocado|0|0| | ... | ... | ... | Based on these two tables, I'm trying to make a table that tells me if my dishes are ok for lactose intolerant people so I can make a menu for my party. I throw a similar party every month and since I add more dishes and ingredients to my tables all the time, the query must be able to keep up without me going back and changing its structure every time. Case-sensitivity does not bother me, but I wouldn't rely on always having commas as separators in "Dish_ingredients".
Asked by Variax (101 rep)
Sep 12, 2023, 02:32 PM
Last activity: Jul 23, 2025, 05:03 PM