[英]MySQL INSERT INTO failing at WHERE clause
好的,我對此很困惑:
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
這是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 | |
+--------------+--------------+------+-----+---------+----------------+
]我已經嘗試了INSERT的一些變體,但是卻一無所獲。 期待有人透露我所缺少的任何明顯的東西!
運行:mysql Ver 14.12 Distrib 5.0.95,用於使用readline 5.1的redhat-linux-gnu(x86_64)(我知道它比較舊,但目前無法升級此框)。
如果您要更新現有行,請執行以下操作:
UPDATE item
SET col1 = 'testing'
WHERE item_name = 'server1';
您沒有正確使用INSERT
語句,如果使用VALUES
子句,則無法在其上應用WHERE
條件。
這是具有適當語法的相同查詢:
INSERT INTO item (col1)
SELECT 'testing'
FROM yourTable
WHERE item_name = 'server1';
希望這會幫助你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.