我有 2 张 table : 表1(条目,x,y) 表2(条目,x,y)
我想更新Table1.position1,所以它= Table2.Position1,其中条目相同(两个表中有不同的条目,但有些是相同的)
所以我尝试做的事情:
update Table1 SET Table1.x = Table2.x where Table1.entry=Table2.entry;
但出现错误:
Unknown column 'Table2.entry' in 'where clause'
然后我尝试进行另一个查询:
update Table1 SET Table1.x=(select x from Table2) inner join Table2 on Table1.entry=Table2.entry;
但又出现错误
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 'inner join Table2 on Table1.entry=Tab' at line 1
谷歌上的任何答案都没有给我满意的结果,所以我希望有人能帮忙。谢谢。
最佳答案
MySQL 中的语法是:
update Table1 t1 join
Table2 t2
on t2.entry = t1.entry
set t1.x = t2.x;
关于mysql - sql 更新几行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51351483/