What's wrong with this query:
INSERT INTO Users( weight, desiredWeight ) VALUES ( 160, 145 ) WHERE id = 1;
It works without the WHERE
clause. I've seemed to have forgot my SQL..
What's wrong with this query:
INSERT INTO Users( weight, desiredWeight ) VALUES ( 160, 145 ) WHERE id = 1;
It works without the WHERE
clause. I've seemed to have forgot my SQL..
correct syntax for mysql insert into statement using post method is:
You can't combine a WHERE clause with a VALUES clause. You have two options as far as I am aware-
INSERT specifying values
INSERT using a SELECT statement
its totall wrong. INSERT QUERY does not have a WHERE clause, Only UPDATE QUERY has it. If you want to add data Where id = 1 then your Query will be
You can't use INSERT and WHERE together. You can use UPDATE clause for add value to particular column in particular field like below code;
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.
If you are specifying a particular record no for inserting data its better to use
UPDATE
statement instead ofINSERT
statement.This type of query you have written in the question is like a dummy query.
Your Query is :-
Here , you are specifying the id=1 , so better you use
UPDATE
statement to update the existing record.It is not recommended to useWHERE
clause in case ofINSERT
.You should useUPDATE
.Now Using Update Query :-