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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
MySQL INSERT Syntax does not support the WHERE clause so your query as it stands will fail. Assuming your
idcolumn is unique or primary key:If you’re trying to insert a new row with ID 1 you should be using:
If you’re trying to change the weight/desiredWeight values for an existing row with ID 1 you should be using:
If you want you can also use INSERT .. ON DUPLICATE KEY syntax like so:
OR even like so:
It’s also important to note that if your
idcolumn is an autoincrement column then you might as well omit it from your INSERT all together and let mysql increment it as normal.