【发布时间】:2012-08-06 18:42:25
【问题描述】:
我正在尝试从特定行的数据更新几行
这是一张表,ItemNum 是唯一的
我的尝试:
UPDATE myTable t, (SELECT DISTINCT width, repeat
FROM myTable
WHERE ItemNum='80644') t1
SET t.width = t1.width
AND SET t.repeat = t1.repeat
WHERE ItemNum='80645'
AND WHERE ItemNum='80646'
给我一个错误#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 myTable WHERE ItemNum='80644') t1 SET t.width' at line 2
当我为单行运行它时,它可以工作
但多行的语法似乎是问题
UPDATE myTable t, (SELECT DISTINCT width
FROM myTable
WHERE ItemNum='80644') t1
SET t.width = t1.width
WHERE ItemNum='80645'
【问题讨论】:
-
这有很多问题。您是否在此处查找了正确的语法:dev.mysql.com/doc/refman/5.0/en/update.html UPDATE table SET t.width=t1.width, t.repeat=t1.repeat WHERE t.ItemNum=# AND t.ItemNum=#;
-
另外你是如何加入你的桌子的?你能展示一些你的mysql架构吗?
标签: mysql sql mysql-error-1064