mysql用table2的属性更新table1的属性

68de4m5k  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(305)

使用以下sql语句时:

UPDATE nsuppliercomponent
INNER JOIN nsuppliercomponent ON supplier.supplierName = nsuppliercomponent.supplierId
SET nsuppliercomponent.supplierId = supplier.supplierId WHERE
nsuppliercomponent.supplierId = supplier.supplierName;

我收到以下错误消息:

Error

SQL query:

UPDATE nsuppliercomponent
INNER JOIN nsuppliercomponent ON supplier.supplierName = nsuppliercomponent.supplierId
SET nsuppliercomponent.supplierId = supplier.supplierId WHERE
nsuppliercomponent.supplierId = supplier.supplierName

MySQL said: Documentation

# 1066 - Not unique table/alias: 'nsuppliercomponent'

我在表A中有2个表,我在表B中存储供应商的所有编号,我存储供应商自己。我想在后面使用foreignkeys来解释为什么我需要将supplierid从tablea中更改,此时所有内容都存储为包含名称的字符串,并使用正确的supplierid将其转换为int
下表:表A:

表B:

icomxhvb

icomxhvb1#

简单的输入错误,我认为,你加入同一个表两次,而不是 supplier 表格:

UPDATE nsuppliercomponent
INNER JOIN supplier ON supplier.supplierName = nsuppliercomponent.supplierId
....

相关问题