MySQL Insert Where query

前端 未结 27 2200
悲&欢浪女
悲&欢浪女 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:42

    If you are specifying a particular record no for inserting data its better to use UPDATE statement instead of INSERT statement.

    This type of query you have written in the question is like a dummy query.

    Your Query is :-

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

    Here , you are specifying the id=1 , so better you use UPDATE statement to update the existing record.It is not recommended to use WHERE clause in case of INSERT.You should use UPDATE .

    Now Using Update Query :-

    UPDATE Users SET weight=160,desiredWeight=145 WHERE id=1;
    

提交回复
热议问题