简体   繁体   English

更新查询给我一个 SQL 错误 (1064)

[英]UPDATE Query Giving me an SQL Error (1064)

I am trying to update a table in my database from another table.我正在尝试从另一个表更新我的数据库中的一个表。 Here is my Syntax, but I can't seem to find any issues with it.这是我的语法,但我似乎找不到任何问题。 I keep getting SQL Error (1064).我不断收到 SQL 错误 (1064)。

UPDATE customers b
SET customers.takerid = customer_update_2016.ot
FROM customer_update_2016 a, customers b
WHERE a.phone = b.phone && a.lname = b.lname

SQL Error (1064): You have an error in your SQL syntax; SQL 错误 (1064):您的 SQL 语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM customer_update_2016 a, customers b WHERE a.phone = b.phone & a.lname =b' at line 3检查与您的 MySQL 服务器版本相对应的手册,在第 3 行的“FROM customer_update_2016 a,customers b WHERE a.phone = b.phone & a.lname =b”附近使用正确的语法

Solution:解决方案:

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 

you have both mysql and sql-server你有 mysql 和 sql-server
which one?哪一个?

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

Follow something like this always始终遵循这样的事情

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];

To solve your problem you should use JOIN, in my case I had to pass data from one table to another like you and this was the way that solved my problem, hope it help with yours and others.(I'm using MariaDB v10.4)要解决您的问题,您应该使用 JOIN,在我的情况下,我必须像您一样将数据从一个表传递到另一个表,这就是解决我的问题的方法,希望它对您和其他人有帮助。(我使用的是 MariaDB v10.5)。 4)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM