MySQL Insert Where query

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

    After WHERE clause you put a condition, and it is used for either fetching data or for updating a row. When you are inserting data, it is assumed that the row does not exist.

    So, the question is, is there any row whose id is 1? if so, use MySQL UPDATE, else use MySQL INSERT.

提交回复
热议问题