Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL将其他表中的id值插入到匹配行中_Mysql_Sql_Database Normalization - Fatal编程技术网

MySQL将其他表中的id值插入到匹配行中

MySQL将其他表中的id值插入到匹配行中,mysql,sql,database-normalization,Mysql,Sql,Database Normalization,我想规范化我的表: products id | name | manufacturer | manufacturer_id manufacturers id | name 我需要一个查询来更新products.manufacturer\u id,其中products.manufacturer=manufacturers.name(然后我将删除products.manufacturer) 非常感谢您抽出时间 汤姆你可以这样试试: update products INNER JOIN manuf

我想规范化我的表:

products
id | name | manufacturer | manufacturer_id

manufacturers
id | name
我需要一个查询来更新products.manufacturer\u id,其中products.manufacturer=manufacturers.name(然后我将删除products.manufacturer)

非常感谢您抽出时间

汤姆

你可以这样试试:

update products INNER JOIN manufacturers
set products.manufacturer_id = manufacturers.id
where products.manufacturer = manufacturers.name
您可以这样尝试:

update products INNER JOIN manufacturers
set products.manufacturer_id = manufacturers.id
where products.manufacturer = manufacturers.name

您没有说的是,
products.manufacturer
未设置,
products.manufacturer\u id
已设置。正确吗?相反,我正在从名称切换到id。您没有说的是
产品。制造商
未设置,而
产品。制造商id
未设置。对吗?恰恰相反-我正在从名字转换为id。@Tomasz:-哦,是的。谢谢。更新了。@Tomasz:-哦,是的。谢谢。更新了。