[英]MySQL INSERT INTO failing at WHERE clause
Ok, I'm stumped on this one: 好的,我对此很困惑:
mysql> INSERT INTO item (col1) VALUES ('testing') WHERE item_name = 'server1';
ERROR 1064 (42000): 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 'WHERE item_name = 'server1'' at line 1
Here's the table desc (slightly sanitized): 这是desc表(略有清洁):
mysql> desc item;
+--------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| item_name | varchar(128) | YES | | | |
| active | int(11) | NO | | 0 | |
| col1 | varchar(512) | YES | | NULL | |
+--------------+--------------+------+-----+---------+----------------+
]I've tried some variations on the INSERT, but I've gotten nowhere. ]我已经尝试了INSERT的一些变体,但是却一无所获。 Look forward to someone revealing whatever obvious thing I'm missing! 期待有人透露我所缺少的任何明显的东西!
Running: mysql Ver 14.12 Distrib 5.0.95, for redhat-linux-gnu (x86_64) using readline 5.1 (I know it's older, but I can't upgrade this box at the moment). 运行:mysql Ver 14.12 Distrib 5.0.95,用于使用readline 5.1的redhat-linux-gnu(x86_64)(我知道它比较旧,但目前无法升级此框)。
If you're looking to update an existing row, it's this: 如果您要更新现有行,请执行以下操作:
UPDATE item
SET col1 = 'testing'
WHERE item_name = 'server1';
You're not using the INSERT
statement correctly, if you use VALUES
clause you can't apply a WHERE
condition on it. 您没有正确使用INSERT
语句,如果使用VALUES
子句,则无法在其上应用WHERE
条件。
Here is the same query with the appropriate syntax: 这是具有适当语法的相同查询:
INSERT INTO item (col1)
SELECT 'testing'
FROM yourTable
WHERE item_name = 'server1';
Hope this will help you. 希望这会帮助你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.