MYSQL 如果类别包含在第二个中则更新状态 table

MYSQL Update Status if Category is Contained In Second table

我有两个 table:食物 t1 和类别 t2 以及 t1 中的一个名为 'ingredient' 的变量 类别 table 包含类别列表,例如水果或蔬菜table

即例如,这是 table 2

ingredient | category
---------------------
apple | fruit 
broccoli | vegetable

我想运行更新查询状态

更新集状态 = [t2 的结果] 在哪里 成分 = [来自 t2 的匹配成分]

因此,如果 t1 中的记录有 'ingredient' = 'broccoli - 它会将状态变量设置为 'vegetable'

这个伪代码使用inner join, left join的语法是什么?

你的表格结构有点不清晰

Update table1
INNER JOIN table2 ON tabl1.ingredient  = taböe2.ingredient 
SET table1.status = table2.categories 
Update food t1
INNER JOIN categories t2 ON t1.ingredient  = t2.ingredient 
SET t1.status = t2.category
;