I have a table like this:
我有这样一张桌子:
name code group
名称代码组
john 12
smith 15
约翰12史密斯15
how do I insert group for a specified row?
如何为指定行插入组?
say for 'smith' I have to insert the group.. i tried to do the following:
说'史密斯'我必须插入组...我试图做以下事情:
INSERT INTO table (group) VALUES ('usher') where code = 15
error: Incorrect syntax near the keyword 'where'.
错误:关键字'where'附近的语法不正确。
please help!!
thanks in anticipation!!
在期待中感谢!!
2 个解决方案
#1
UPDATE mytable
SET group = 'usher'
WHERE code = 15
#2
As mentioned in the previous answer you want to perform an UPDATE not an INSERT.
如前面的答案所述,您希望执行UPDATE而不是INSERT。
UPDATE is used to change existing rows while INSERT will create new rows. Hence why WHERE can not be used with an INSERT statement.
UPDATE用于更改现有行,而INSERT将创建新行。因此,为什么WHERE不能与INSERT语句一起使用。
#1
UPDATE mytable
SET group = 'usher'
WHERE code = 15
#2
As mentioned in the previous answer you want to perform an UPDATE not an INSERT.
如前面的答案所述,您希望执行UPDATE而不是INSERT。
UPDATE is used to change existing rows while INSERT will create new rows. Hence why WHERE can not be used with an INSERT statement.
UPDATE用于更改现有行,而INSERT将创建新行。因此,为什么WHERE不能与INSERT语句一起使用。