我想规范化我的表格:
products
id | name | manufacturer | manufacturer_id
manufacturers
id | name
我需要查询来更新products.manufacturer_id,其中products.manufacturer = manufacturers.name(我将删除products.manufacturer)
非常感谢你的时间
汤姆
答案 0 :(得分:3)
您可以尝试这样:
update products INNER JOIN manufacturers
set products.manufacturer_id = manufacturers.id
where products.manufacturer = manufacturers.name
答案 1 :(得分:1)
update products p
set p.manufacturer_id =
(select m.id from manufacturers m where m.name = p.manufacturer)