SQL 从脚本更新中有语法错误?
SQL Syntax error in Update from script?
我正在尝试将一列从一列 table 更新到另一列中的同一列。
我有两个 table:
容器(id,barcode_1,位置)
测试(id,barcode_1,位置)
两个 table 完全相同,除了 barcode_1 列。我想用 test.barcode_1 中所有匹配 ID 的值更新 container.barcode_1。
这是我正在使用的代码:
update container
set container.barcode_1 = test.barcode_1
FROM container INNER JOIN test ON container.id = test.id;
当我 运行 那个代码时,我得到这个错误:
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM container INNER JOIN test ON container.id = test.id' at line 3
知道为什么这可能会失败吗?
您的 UPDATE
语法在这里是错误的。应该是
update container
INNER JOIN test ON container.id = test.id
set container.barcode_1 = test.barcode_1;
(或)使用 table 别名
update container c
INNER JOIN test t ON c.id = t.id
set c.barcode_1 = t.barcode_1;
我正在尝试将一列从一列 table 更新到另一列中的同一列。
我有两个 table:
容器(id,barcode_1,位置)
测试(id,barcode_1,位置)
两个 table 完全相同,除了 barcode_1 列。我想用 test.barcode_1 中所有匹配 ID 的值更新 container.barcode_1。
这是我正在使用的代码:
update container
set container.barcode_1 = test.barcode_1
FROM container INNER JOIN test ON container.id = test.id;
当我 运行 那个代码时,我得到这个错误:
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM container INNER JOIN test ON container.id = test.id' at line 3
知道为什么这可能会失败吗?
您的 UPDATE
语法在这里是错误的。应该是
update container
INNER JOIN test ON container.id = test.id
set container.barcode_1 = test.barcode_1;
(或)使用 table 别名
update container c
INNER JOIN test t ON c.id = t.id
set c.barcode_1 = t.barcode_1;