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..
i dont think that we can use where clause in insert statement
I think your best option is use REPLACE instead INSERT
DO READ THIS AS WELL
It doesn't make sense... even literally
INSERT
means add anew row
and when you sayWHERE
you define which row are you talking about in theSQL
.So adding a new row is not possible with a condition on an existing row.
You have to choose from the following:
A. Use
UPDATE
instead ofINSERT
B. Use
INSERT
and removeWHERE
clause ( I am just saying it...) or if you are real bound to useINSERT
andWHERE
in a single statement it can be done only via INSERT..SELECT clause...But this serves an entirely different purpose and if you have defined id as Primary Key this insert will be failure, otherwise a new row will be inserted with id = 1.
Insert into = Adding rows to a table
Upate = update specific rows.
What would the where clause describe in your insert? It doesn't have anything to match, the row doesn't exist (yet)...
It depends on the situation INSERT can actually have a where clause.
For example if you are matching values from a form.
Makes sense doesn't it?