Mysql 更新查询给我一个SQL错误(1064)
我正在尝试从另一个表更新数据库中的一个表。这是我的语法,但我似乎找不到任何问题。我一直收到SQL错误(1064) SQL错误(1064):您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以获得正确的语法,以便在第3行的“FROM customer_update_2016 a,customers b,其中a.phone=b.phone&a.lname=b”附近使用 解决方案:Mysql 更新查询给我一个SQL错误(1064),mysql,sql-update,Mysql,Sql Update,我正在尝试从另一个表更新数据库中的一个表。这是我的语法,但我似乎找不到任何问题。我一直收到SQL错误(1064) SQL错误(1064):您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以获得正确的语法,以便在第3行的“FROM customer_update_2016 a,customers b,其中a.phone=b.phone&a.lname=b”附近使用 解决方案: UPDATE customers INNER JOIN customer_update_2016 ON c
UPDATE customers
INNER JOIN customer_update_2016
ON customers.phone = customer_update_2016.phone
AND customers.lname = customer_update_2016.lname
SET customers.takerid = customer_update_2016.ot
您同时拥有mysql和sql server
哪一个
UPDATE customers
SET customers.takerid = customer_update_2016.ot
FROM customers
JOIN customer_update_2016
on customers.phone = customer_update_2016.phone
and customers.lname = customer_update_2016.lname
and customers.takerid <> customer_update_2016.ot
更新客户
SET customers.takerid=customer\u update\u 2016.ot
来自客户
加入2016年客户更新
on customers.phone=customer\u update\u 2016.phone
and customers.lname=customer\u update\u 2016.lname
和客户。takerid customer_update_2016.ot
始终遵循这样的操作
UPDATE [table1_name] AS t1
INNER JOIN [table2_name] AS t2
ON t1.[column1_name] = t2.[column1_name]
SET t1.[column2_name] = t2.[column2_name];
为了解决您的问题,您应该使用JOIN,在我的例子中,我必须像您一样将数据从一个表传递到另一个表,这就是解决我问题的方法,希望它对您和其他人有所帮助。(我使用的是MariaDB v10.4)
我认为您缺少一个在查询中使用多个表的
JOIN
。示例:可能重复,那么这真的有效吗?我指的是说解决方案的那部分?或者这就是您试图解决问题的解决方案?当我运行此查询时,我得到:SQL错误(1064):您的SQL语法有错误;请查看与您的MySQL服务器版本对应的手册,以了解第3行“FROM customers JOIN customer_update_2016 on customers.phone=cu”附近使用的正确语法,确保这适用于sql server。你把它两边都贴上了标签。
UPDATE [table1_name] AS t1
INNER JOIN [table2_name] AS t2
ON t1.[column1_name] = t2.[column1_name]
SET t1.[column2_name] = t2.[column2_name];
UPDATE
table1
LEFT JOIN table2 AS tb2
ON tb2.fieldThatJoin = table1.fieldThatJoin//this part indicate the field that join them
SET
table1.field1 = tb2.field1;
//if you want to update more than one field then do this
table1.field1 = tb2.field1,
table1.field2 = tb2.field2,
table1.field3 = tb2.field3;//remember to put the ';' at the end