Updating multiple columns
Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.Visit Stack Exchange Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Sign up to join this community UPDATE some_table SET column_x = CASE WHEN x_specific_condition THEN new_value_for_x ELSE column_x END, column_y = CASE WHEN y_specific_condition THEN new_value_for_y ELSE column_y END, WHERE some_more_conditions Problem with above is, each column (x, y) still gets updated with their own value if some_more_conditions return true irrespective of their specific conditions returning true.Hi Site Point members I have been perusing through the solutions for "updating multiple rows with one query", but I have a pressing question: How would one "SET" multiple column values with one query?Here is my example..normal update command would be: // question ID ranges from 1-20 // $questionid == 1, $member_id==1 UPDATE table_Foo Bar SET answer One='$ans1Val', answer Two='$ans2Val', answer Three='$ans3Val' WHERE member_id='$memberid' AND question_id='$questionid'; // $questionid == 2, $member_id==1 UPDATE table_Foo Bar SET answer One='$ans1Val', answer Two='$ans2Val', answer Three='$ans3Val' WHERE member_id='$memberid' AND question_id='$questionid'; ..
table_member ( member_id, taking Foobar, foobar Completed, foobar Start Time, foobar End Time ) //foobar is actually a "results" table.UPDATE table_Foo Bar SET answer One='yes', answer Two='no', answer Three='yes' WHERE member_id = 1 AND question_id = 1; UPDATE table_Foo Bar SET answer One='no', answer Two='no', answer Three='yes' WHERE member_id = 1 AND question_id = 2; UPDATE table_Foo Bar SET answer One='yes', answer Two='yes', answer Three='no' WHERE member_id = 1 AND question_id = 3; oh, absolutely!!your problem likely lies in the php code, something about constructing variables and looping (i'm guessing -- i don't do php so i only gave your code a cursory glance) however, since you asked this question in the mysql forum, let me give you a mysql answer redesign your table, normalize it to first normal form you have repeating columns in answer One, answer Two, answer Three these should be three rows in a normalized table from there, the php will be slightly different Hello r937! To address your normalization suggestion, here is my table structure (it goes into a tiny bit more detail; my first example was a very generalized one, this one is also generalized to a certain extent) - and there is a specific reason why I have designed it so...which I will explain in a bit.The problem I find with that structure is there are at the same time an variable number of questions and an variable number of answers plus multiple answers for a single individual that need to be recorded. Unfortunately, I was tasked to present the survey in the format shown in the screenshot below, which is why I chose to design the table structures the way I did.
Thing is, there have been no concerns about normalization as I have had no problems with data insertion, querying results, reporting the answers, association of answers with members, etc!
returns TRUE for all columns in INSERT actions because the columns have either explicit values or implicit (NULL) values inserted.