About this question
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 forgotten 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 forgotten my SQL...
Log in to share your answer and help other learners.
Log in to answerBest Answer · By JanBask Data Science Expert
Answered on Jul 15, 2021
MySQL INSERT Syntax does not support the insert where clause so your query as it stands will fail. Assuming your id column is unique or primary key:
If you want to insert a new row with ID 1 then you use the below query:
INSERT INTO Users(id, weight, desiredWeight) VALUES(1, 160, 145);
But, If want to change the weight/desiredWeight values for an existing row with ID 1 then, use the below query:
UPDATE Users SET weight = 160, desiredWeight = 145 WHERE id = 1;
If you are trying to use INSERT .. ON DUPLICATE KEY syntax then, do like this:
INSERT INTO Users (id, weight, desiredWeight) VALUES(1, 160, 145) ON DUPLICATE KEY UPDATE weight=160, desiredWeight=145Or do this:
INSERT INTO Users SET id=1, weight=160, desiredWeight=145 ON DUPLICATE KEY UPDATE weight=160, desiredWeight=145Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.
Step-by-step Data Science guides from industry experts
Common Data Science interview questions, answered
Guides, tips and career advice on Data Science from JanBask experts.
Data Science The Best Data Science Projects (Beginner To Advanced)
Discover 15 data science project ideas from beginner to advanced levels. Includes tech stacks, time estimates, & real-use cases.…
Data Science Data Science vs Software Engineering - What you should know?
Compare Data Science vs. Software Engineering - explore skills, tools, roles, salaries, and career scope. Discover which tech…
Data Science Top 15 Deep Learning Algorithms You Must Know in 2025
Discover the top 15 deep learning algorithms powering AI in 2025. Learn how deep learning models, DL models, and deep machine…
Data Science Deep Learning Tutorial Guide for Beginners
Deep Learning, Machine Learning & Artificial Intelligence have become trending words of the IT sector today.