MySQL Insert Where query

前端 未结 27 2322
悲&欢浪女
悲&欢浪女 2020-11-22 06:16

What\'s wrong with this query:

INSERT INTO Users( weight, desiredWeight ) VALUES ( 160, 145 ) WHERE id = 1;

It works without the WHE

27条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 06:55

    You simply cannot use WHERE when doing an INSERT statement:

     INSERT INTO Users( weight, desiredWeight ) VALUES ( 160, 145 ) WHERE id = 1;
    

    should be:

     INSERT INTO Users( weight, desiredWeight ) VALUES ( 160, 145 );
    

    The WHERE part only works in SELECT statements:

    SELECT from Users WHERE id = 1;
    

    or in UPDATE statements:

    UPDATE Users set (weight = 160, desiredWeight = 145) WHERE id = 1;
    

提交回复
热议问题