【问题标题】:UPDATE Query Giving me an SQL Error (1064)更新查询给我一个 SQL 错误 (1064)
【发布时间】:2016-05-25 13:22:14
【问题描述】:

我正在尝试从另一个表更新我的数据库中的一个表。这是我的语法,但我似乎找不到任何问题。我不断收到 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 错误 (1064):您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 3 行的“FROM customer_update_2016 a, customers b WHERE a.phone = b.phone & a.lname =b”附近使用正确的语法

解决方案:

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-update


【解决方案1】:

你有 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

【讨论】:

  • 当我运行这个查询时,我得到: SQL 错误 (1064): 你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 3 行的“FROM customers JOIN customer_update_2016 on customers.phone = cu”附近使用正确的语法
  • 很确定这适用于 sql-server。您已将其标记为双向。
【解决方案2】:

始终关注这样的事情

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

【讨论】:

    【解决方案3】:

    要解决您的问题,您应该使用 JOIN,在我的情况下,我必须像您一样将数据从一个表传递到另一个表,这就是解决我的问题的方法,希望它对您和其他人有所帮助。(我正在使用MariaDB v10.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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-16
      • 1970-01-01
      • 2015-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多