You can do it this way:

UPDATE table_users
    SET cod_user = (case when user_role = 'student' then '622057'
                         when user_role = 'assistant' then '2913659'
                         when user_role = 'admin' then '6160230'
                    end),
        date = '12082014'
    WHERE user_role in ('student', 'assistant', 'admin') AND
          cod_office = '17389551';

I don't understand your date format. Dates should be stored in the database using native date and time types.

Answer from Gordon Linoff on Stack Overflow
Discussions

mysql - SQL update multiple rows with same value - Stack Overflow
I use this to update (add points) rows which mgroup is 15 UPDATE ibf_members SET points = points + 500 WHERE mgroup = 15 What can I use to update (add points + 500) for rows which has its id as 5,... More on stackoverflow.com
🌐 stackoverflow.com
May 22, 2017
sql - Multiple Updates in MySQL - Stack Overflow
I know that you can insert multiple rows at once, is there a way to update multiple rows at once (as in, in one query) in MySQL? Edit: For example I have the following Name id Col1 Col2 Row1 ... More on stackoverflow.com
🌐 stackoverflow.com
Updating multiple columns and multiple rows with one MySQL query - Databases - SitePoint Forums | Web Development & Design Community
Hi SitePoint 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…the normal update command would be: UPDATE table_FooBar SET ... More on sitepoint.com
🌐 sitepoint.com
0
April 5, 2011
mysql update multiple columns with same now() - Stack Overflow
Remember these same variables can be inserted as inputs in a form on the front-end of the application. That makes the project dynamic and not static. Secondly if now() indicates time of update then using mysql you can decalre the property of the row as a timestamp. More on stackoverflow.com
🌐 stackoverflow.com
🌐
DEV Community
dev.to › azophy › how-to-update-multiple-rows-based-on-list-of-key-val-pairs-in-mysql-mariadb-postgresql-4lpp
How to update multiple rows based on list of key-val pairs (in MySQL, MariaDB, & PostgreSQL) - DEV Community
September 29, 2023 - MariaDB's VALUES clause is shorter as it doesn't use the ROW keyword at all · UPDATE table_name SET changed_col = temp_data.column1 FROM (VALUES ('key1', 'val1'), ('key2', 'val2'), .... ) as temp_data WHERE comparison_col = temp_data.column0 · Postgres definitely have the best syntax among the three, as it support aliasing column names for VALUES syntax, just as SQL Server did · UPDATE table_name SET changed_col = temp_data.col_name_1 FROM (VALUES ('key1', 'val1'), ('key1', 'val2'), ...
🌐
Quora
quora.com › How-can-you-update-multiple-records-in-MySQL-with-one-query
How to update multiple records in MySQL with one query - Quora
Use when the same change applies to all matched rows. UPDATE table_name SET col = 'same_value' WHERE condition; Simple and efficient; uses full-table or index scan depending on WHERE. 5) INSERT ... ON DUPLICATE KEY UPDATE — upsert multiple rows
🌐
TablePlus
tableplus.com › blog › 2018 › 11 › how-to-update-multiple-rows-at-once-in-mysql.html
How to update multiple rows at once in MySQL? | TablePlus
November 12, 2018 - INSERT INTO students (id, score1, score2) VALUES (1, 5, 8), (2, 10, 8), (3, 8, 3), (4, 10, 7) ON DUPLICATE KEY UPDATE score1 = VALUES(score1), score2 = VALUES(score2); Need a good GUI Tool for MySQL? TablePlus is a modern, native tool with an elegant UI that allows you to simultaneously manage ...
🌐
TutorialsPoint
tutorialspoint.com › How-can-we-update-columns-values-on-multiple-rows-with-a-single-MySQL-UPDATE-statement
How can we update columns values on multiple rows with a single MySQL UPDATE statement?
mysql> UPDATE tender SET rate = rate + 1000 WHERE tender_id >= 300; Query OK, 4 rows affected (0.07 sec) Rows matched: 4 Changed: 4 Warnings: 0 mysql> Select * from tender; +-----------+---------+------+ | tender_id | company | rate | +-----------+---------+------+ | 200 | ABC | 1000 | | 300 | ABD | 6000 | | 301 | ABE | 7000 | | 302 | ABF | 3500 | | 303 | ABG | 3600 | +-----------+---------+------+ 5 rows in set (0.00 sec) We can observe from the above result set that the values in multiple rows, having tender_id >= 300, has been updated.
🌐
Etutorialspoint
etutorialspoint.com › index.php › mysql-exercises › mysql-update-multiple-rows-in-one-query
MySQL update multiple rows in one query
The best way to update multiple rows in just one statement is use CASE WHEN ELSE statement. In this, the statement will update the matched case and end otherwise, like- UPDATE 'table_name' SET 'field_name' = CASE 'id' WHEN '1' THEN 'value 1' WHEN '2' THEN 'value 2' WHEN '3' THEN 'value 3' ELSE ...
Find elsewhere
🌐
Medium
medium.com › geekculture › update-multiple-rows-in-sql-with-different-values-at-once-7d2eddb0b85f
Update multiple rows in SQL with different values at once | by Tadej Golobic | Geek Culture | Medium
June 12, 2021 - But how? Well, did you know, that we can use JOIN in the UPDATE statement? Yes, we can. So, we will join this data from this select statements and set our firstName as new value and id as our condition like this
🌐
SitePoint
sitepoint.com › databases
Updating multiple columns and multiple rows with one MySQL query - Databases - SitePoint Forums | Web Development & Design Community
April 5, 2011 - Here is my example…the normal update command would be: UPDATE table_FooBar SET answerOne='$ans1Val', answerTwo='$ans2Val', answerThree='$ans3Val' WHERE member_id='$memberid' AND question_id='$questionid'; Now I have to do this for up to 20 ...
🌐
GeeksforGeeks
geeksforgeeks.org › mysql › how-to-update-multiple-rows-in-a-single-query-in-mysql
How to UPDATE Multiple ROWs in a Single Query in MySQL? - GeeksforGeeks
July 23, 2025 - Therefore updating multiple rows in a single query in MySQL can be efficiently done using the UPDATE statement having a WHERE clause in it. This WHERE clause is used to specify the criteria for records that you want to update.
🌐
Edureka Community
edureka.co › home › community › categories › web development › php › mysql - update multiple rows with different...
MySQL - UPDATE multiple rows with different values in one query | Edureka Community
June 1, 2020 - Hello, I wanted to know how to UPDATE multiple rows with different values and I just don't get it ... in the WHERE and in the IF condition.Any ideas?
🌐
w3resource
w3resource.com › mysql › update-table › update-table.php
MySQL UPDATE - w3resource
February 28, 2026 - The following MySQL statement will update the 'receive_qty' column of newpurchase table with a new value 20. -- This SQL statement updates the receive_qty column in the newpurchase table UPDATE newpurchase -- Setting the receive_qty column to the value 20 for all rows SET receive_qty = 20;
🌐
Quora
quora.com › How-can-I-update-multiple-rows-columns-in-MySQL-with-one-query
How to update multiple rows & columns in MySQL with one query - Quora
UPDATE table_name SET column_name = CASE id WHEN 1 THEN 'value1' WHEN 2 THEN 'value2' ... Software Engineer at Cranes Software International Limited (2017–present) · Author has 129 answers and 219K answer views · 5y · Originally Answered: How do you update multiple rows in a single query? · · If we have to change or update same column's data for all rows then you can go with based on primary key Id...
Top answer
1 of 2
6

Remarks

It is possible to update rows based on some condition. It is also possible to update multiple tables in one statement in MySQL.

Whether the latter is a good idea is debatable, though. The target tables would be joined together for the update, and when I say "joined", I mean it in a broader sense: you do not have to specify a joining condition, in which case theirs would be a cross join. In a cross join, when at least one of the tables has more than one row, the other table will inevitably have its rows duplicated in the joined set. If both have multiple rows, both will have them multiplied. Somewhat counter-intuitively, MySQL will still update each affected row just once, yet I would refrain from multi-table updates in such scenarios, even if solely because of the counter-intuitiveness.

Method 1

Anyway, moving on to your specific example, there is indeed no joining condition, only a filter on each table. You can specify those filters in the WHERE clause of the UPDATE. Now in order to select which value to update each column with, you can use a CASE expression. This is what the complete UPDATE statement might look like:

UPDATE
  A, B
SET
  A.col1 = 'abc',
  A.col2 = 'xyz',
  B.col1 = CASE B.col3
             WHEN '1' THEN 'a'
             WHEN '2' THEN 'b'
             WHEN '3' THEN 'c'
           END,
  B.col2 = CASE B.col3
             WHEN '1' THEN 'x'
             WHEN '2' THEN 'y'
             WHEN '3' THEN 'z'
           END
WHERE
  A.col3 = '1'
  AND B.col3 IN ('1', '2', '3')
;

You can see that you have to repeat the same set of conditions in a CASE expression both for B.col1 and for B.col2. Is there a way to avoid that?

Method 2

Yes, there is. You can arrange the target values for B.col1 and B.col2 as well as the filtering values for B.col3 as a derived table and join it to B in the UPDATE clause, like this:

UPDATE
  A,
  B
    INNER JOIN
    (
      SELECT 'a' AS col1, 'x' AS col2, '1' AS col3
      UNION ALL
      SELECT 'b', 'y', '2'
      UNION ALL
      SELECT 'c', 'z', '3'
    ) AS fltr ON B.col3 = fltr.col3
SET
  A.col1 = 'abc',
  A.col2 = 'xyz',
  B.col1 = fltr.col1,
  B.col2 = fltr.col2
WHERE
  A.col3 = '1'
;

The join is also acting as a filter for B, so you can omit the one in the WHERE clause.

You can find a demo for each method at db<>fiddle:

  • Method 1
  • Method 2

Better way

Finally, as have been remarked both at the beginning of this post and in the comments, you can have a separate UPDATE statement for each table. The result would be clear in intention both to the reader of your script and to the database engine. A simpler script enables the latter to have more options for optimisation.

Use either of the methods above for the table B update, but do both tables separately:

UPDATE
  A
SET
  A.col1 = 'abc',
  A.col2 = 'xyz'
WHERE
  A.col3 = '1'
;
UPDATE
  B
    INNER JOIN
    (
      SELECT 'a' AS col1, 'x' AS col2, '1' AS col3
      UNION ALL
      SELECT 'b', 'y', '2'
      UNION ALL
      SELECT 'c', 'z', '3'
    ) AS fltr ON B.col3 = fltr.col3
SET
  B.col1 = fltr.col1,
  B.col2 = fltr.col2
;

There is also another reason for splitting the updates in separate statements. Since for a single UPDATE statement the tables need to be joined, it is important that both tables have rows intended for the update. If one table has no matching rows, then, even if the other does, neither will be updated. This is because an empty set cross-joined to a non-empty set still results in an empty set.

So, the single UPDATE statement would have no rows to work with if at least one table had no rows matching the condition(s). That would not happen with separate UPDATEs, because each would work with its own table regardless of the contents of the other, therefore, absence of rows in one table would not affect the update of the other.

2 of 2
0

You can use below one for one table if you want to update many columns of one table.

UPDATE table
SET col1 = CASE WHEN col3 = 'name1' THEN 'a' 
            WHEN col3 = '2' THEN b 
            ELSE 0 
       END
 , col2 = CASE WHEN col3 = '1' THEN 'b' 
           WHEN col3 = 'name2' THEN 'c' 
           ELSE '' 
      END
;
🌐
Scaler
scaler.com › home › topics › how to update multiple columns in mysql?
How To Update Multiple Columns in MySQL? - Scaler Topics
July 7, 2023 - However, if you forget to implement the WHERE clause, it shall then accidentally also update all rows in the table. In this section of the article, we shall be covering the example of how one can update multiple columns in MySQL. Before we start to update multiple columns in MySQL, let us create a table named "School" with few records, as seen in the code below. ... Explanation: We will have four columns in the table School. Here, we have specified the Students_Name with the UNIQUE constraint to make sure that no value is duplicated in this column.
🌐
SitePoint
sitepoint.com › databases
Multiple UPDATE, same column, different values, different WHERE conditions - Databases - SitePoint Forums | Web Development & Design Community
August 9, 2008 - I’ve found plenty of info around about updating multiple rows with the same value using “WHERE columname IN”, and I’ve got that down. But, I’m needing to UPDATE a column in multiple rows with a different value for each WHERE condition. My updates are being done as individual queries like this: UPDATE tablename SET widget='zamu-xxx' WHERE widget='zamu'; UPDATE tablename SET widget='flabu-yyy' WHERE widget='flabu'; Is there any way to do something like this in a single query?
🌐
NAO IT Systems LLC.
digibeatrix.com › home › mysql › sql basics › mysql update multiple rows and columns: complete guide with case, join, and performance tips
MySQL UPDATE Multiple Rows and Columns: Complete Guide with CASE, JOIN, and Performance Tips - Practical MySQL & MariaDB
February 7, 2026 - Learn how to use MySQL UPDATE to modify multiple rows and columns efficiently. Includes examples with WHERE, IN, OR, CASE, JOIN, transactions, indexing, and performance optimization tips.