Run a select to make sure it is what you want

SELECT t1.value AS NEWVALUEFROMTABLE1,t2.value AS OLDVALUETABLE2,*
FROM Table2 t2
INNER JOIN Table1 t1 on t1.ID = t2.ID

Update

UPDATE Table2
SET Value = t1.Value
FROM Table2 t2
INNER JOIN Table1 t1 on t1.ID = t2.ID

Also, consider using BEGIN TRAN so you can roll it back if needed, but make sure you COMMIT it when you are satisfied.

Answer from user1166147 on Stack Overflow
🌐
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
Discussions

mysql - SQL - Update multiple records in one query - Stack Overflow
CREATE TABLE #temp (id int, name ... #temp select * from #temp2 drop table #temp drop table #temp2 ... database complies a query pattern you provide the first time, keep the compiled result for current connection (depends on implementation). then you updates all the rows, by sending shortened label of the prepared function with different parameters in SQL syntax, instead ... More on stackoverflow.com
🌐 stackoverflow.com
sql server - Update one table's row from the results of multiple rows of another table - Database Administrators Stack Exchange
I've seen posts on how to update multiple rows (specifically using case?), but my question is the inverse. I have a table of phone_numbers Person_ID Phone_number 1 102-345-6789 1 102-445-6789 2 102... More on dba.stackexchange.com
🌐 dba.stackexchange.com
January 5, 2023
If I select multiple rows in a table, how do I mass update them in Retool PostgreSQL database?
Hi everyone, I'm using the Retool PostgreSQL database. How do I mass update multiple rows from a table where I select several of them? Can't seem to get this to work. I have a table called table11 and if I select 3 rows for example, I see that "SelectedRowKeys" shows all 3 like: 0 ... More on community.retool.com
🌐 community.retool.com
1
0
June 24, 2023
Update multiple selected rows in a tablle using sql update? or any other way (rest api)?
HI Team, as in the subject. I have been struggling to update multiple rows in a postgresql DB table, which is brought to retool by a select * statement and represented in a table. I'd like to update multiple rows in the target PostgreSQL DB by selecting them in a table that shows a parsed CSV. More on community.retool.com
🌐 community.retool.com
0
0
January 28, 2022
🌐
Stack Exchange
dba.stackexchange.com › questions › 321768 › update-one-tables-row-from-the-results-of-multiple-rows-of-another-table
sql server - Update one table's row from the results of multiple rows of another table - Database Administrators Stack Exchange
January 5, 2023 - UPDATE c SET c.phone_number_1 = IIF(ISNULL(c.phone_number_1, '') = '', [1], c.phone_number_1) , c.phone_number_2 = IIF(ISNULL(c.phone_number_1, '') != '', [2], c.phone_number_2) FROM #contacts AS c CROSS APPLY ( SELECT [1] , [2] FROM ( SELECT pn.phone_number , ROW_NUMBER() OVER (PARTITION BY pn.id ORDER BY pn.id) AS rn FROM #phone_numbers AS pn WHERE c.id = pn.id ) AS pn_order PIVOT ( MAX(phone_number) FOR rn IN ([1], [2]) ) pn_pvt ) AS pn_display WHERE ( ISNULL(c.phone_number_1, '') = '' AND ISNULL([1], '') != '' ) OR ( ISNULL(c.phone_number_2, '') = '' AND ISNULL([2], '') != '' );
🌐
Retool
community.retool.com › 💬 queries and resources
If I select multiple rows in a table, how do I mass update them in Retool PostgreSQL database? - 💬 Queries and Resources - Retool Forum
June 24, 2023 - Hi everyone, I'm using the Retool PostgreSQL database. How do I mass update multiple rows from a table where I select several of them? Can't seem to get this to work. I have a table called table11 and if I select 3 rows for example, I see that "SelectedRowKeys" shows all 3 like: 0 "9a7be3ad-ae74-4518-9214-5fe8424f3644" 1 "8f1ee9ea-76fe-48c1-8928-4f00c935b4d7" 2 "8ac0ca46-35b5-409d-8921-a7f93281c374" Where those values are from the "id" Primary Key column.
🌐
GeeksforGeeks
geeksforgeeks.org › sql › how-to-update-multiple-records-using-one-query-in-sql-server
How to Update Multiple Records Using One Query in SQL Server? - GeeksforGeeks
Using the SQL UPDATE statement with the WHERE clause users can update multiple records in the table based on some condition.
Published   July 23, 2025
Find elsewhere
🌐
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 - Indeed, if you have the data in CSV format, or you have direct access to the database, its easier to just import it using dedicated SQL toolbox. However as this is not always the case, I think this article should be valuable, at least for myself in the future. Hope it helps ... I like java, gentoo linux and open source. ... For MariaDB the example does not works with my database. I found two ways update multiple rows. It is a hassle, but works. ... UPDATE table_name, ( WITH tmp_table(column0,column1) AS ( VALUES ('val0col0', 'val0col1), ('val1col0', 'val1col1), .... ) SELECT * FROM tmp_table) tmp_table SET table_name.column1 = tmp_table.column1 WHERE table_name.column0 = tmp_table.column0;
🌐
W3Schools
w3schools.com › sql › sql_update.asp
SQL UPDATE Statement
The following SQL updates the record with CustomerID = 1, with a new contact person AND a new city. UPDATE Customers SET ContactName = 'Alfred Schmidt', City= 'Frankfurt' WHERE CustomerID = 1; The selection from the "Customers" table will now look like this:
🌐
Retool
community.retool.com › 💬 queries and resources
Update multiple selected rows in a tablle using sql update? or any other way (rest api)? - 💬 Queries and Resources - Retool Forum
January 28, 2022 - HI Team, as in the subject. I have been struggling to update multiple rows in a postgresql DB table, which is brought to retool by a select * statement and represented in a table. I'd like to update multiple rows in the…
🌐
Quora
quora.com › How-do-I-update-multiple-rows-of-a-single-column-in-SQL
How to update multiple rows of a single column in SQL - Quora
Answer: Actually that’s real easy. The problem is trying NOT to update the rows you don’t want updated. Let’s assume that you have a column where a few, many or all of the values have a NULL value, but, for whatever reason they should have a value like true or false.
Top answer
1 of 2
8

Couldn't find a SQL Server 2008 fiddle engine so I had to opt for a SQL Server 2014 ... so not sure if the following will work in SQL Server 2008, but fwiw ...

Setup some sample data:

create table Table1(id int, Date datetime null);
create table Table2(id int, Date datetime);

insert Table1 values (1,null)
insert Table1 values (1,null)
insert Table1 values (2,null)
insert Table1 values (2,null)
insert Table1 values (2,null);

insert Table2 values (1,'2013-01-29 08:50:00.000')
insert Table2 values (1,'2013-01-29 15:28:00.000')
insert Table2 values (2,'2013-01-31 11:56:00.000')
insert Table2 values (2,'2013-03-11 16:08:00.000')
insert Table2 values (2,'2013-01-31 14:04:00.000');

Keeping in mind that we haven't been provided (yet) with any means to determine which rows to match between Table1 and Table2 for a given id value, I'll just let row_number() generate a 'matching' rowid.

And then we'll make use of SQL Server's ability to update Table1 via a derived table definition:

update T1 
set    T1.Date=T2.Date

from   (select row_number() over(partition by id order by Date) as rowid,
               id,
               Date
        from   Table1 
        where  Date is NULL) T1

join   (select row_number() over(partition by id order by Date) as rowid,
               id,
               Date
        from   Table2) T2

on      T1.id    = T2.id
and     T1.rowid = T2.rowid;

And the results:

select * from Table1;

id  Date
--- --------------------
1   2013-01-29T08:50:00Z
1   2013-01-29T15:28:00Z
2   2013-01-31T11:56:00Z
2   2013-01-31T14:04:00Z
2   2013-03-11T16:08:00Z

And here's a SQL Fiddle for the above.

2 of 2
3

You stated that the order of the matching matters but it seems like you don't have anything to ORDER BY in table 1 to create a guaranteed order to match the other table and there is no way in SQL Server to order the rows after insertion date, because information about that is not stored. With this in mind it’s not possible to do a matching with the result you want. There is a solution to update the rows with an arbitrary match within each id. If that would be good enough.

UPDATE t 
SET    t.[date] = tt.[date] 
FROM   (SELECT *, 
               Row_number() 
                 OVER ( 
                   partition BY id 
                   ORDER BY [date]) AS rno 
        FROM   Table1) AS t 
       INNER JOIN (SELECT *, 
                          Row_number() 
                            OVER ( 
                              partition BY id 
                              ORDER BY [date]) AS rno 
                   FROM   Table2) AS tt 
               ON t.id = tt.id 
                  AND t.rno = tt.rno 

This solution will match all rows individually but can't guarantee the order.

DB Fiddle

🌐
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 - 1. You can either write multiple UPDATE queries like this and run them all at once: UPDATE students SET score1 = 5, score2 = 8 WHERE id = 1; UPDATE students SET score1 = 10, score2 = 8 WHERE id = 2; UPDATE students SET score1 = 8, score2 = 3 WHERE id = 3; UPDATE students SET score1 = 10, score2 ...
🌐
Tooljet
docs.tooljet.com › bulk update multiple rows in table
Bulk Update Multiple Rows in Table | ToolJet
Star our repository on GitHub to stay updated with new features and contribute to our platform! ... For the purpose of this guide, it's presumed that you've already established a successful connection to your data source. We'll use PostgreSQL for this example, but you can adjust the queries based on the SQL database that you are using. Create a PostgreSQL query in SQL mode, rename it to users and enter the below code. SELECT * FROM <table name> // *replace <table name> with your table name*
Top answer
1 of 2
5

You could supply the new values as a table (with the help of the VALUES row constructor), so that you could join it with the target table and use the join in the UPDATE statement, like this:

UPDATE
  tgt
SET
  Column1 = src.Column1,
  Column2 = src.Column2,
  Column3 = src.Column3,
  ...
FROM
  dbo.TargetTable AS tgt
  INNER JOIN
  (
    VALUES
    (1, 'a', 'k', 'x', ...),
    (2, 'b', 'l', 'y', ...),
    (3, 'c', 'm', 'z', ...)
  ) AS src (ID, Column1, Column2, Column3, ...)
    ON tgt.ID = src.ID
;
2 of 2
5

An example of how this can be done (see SQLFiddle here):

(p.s. I used a CTE (aka the WITH clause) and PostgreSQL (I don't use MS SQL Server) but the principles are very much the same - except for the SERIAL datatype - use MS's auto-incrementing type!).

Create and populate a source table (named one):

CREATE TABLE one
(
  record_id SERIAL,
  one_first_var INTEGER,
  one_second_var INTEGER,
  one_third_var INTEGER
);

INSERT INTO one (one_first_var, one_second_var, one_third_var) VALUES (1, 1, 1);
INSERT INTO one (one_first_var, one_second_var, one_third_var) VALUES (2, 2, 2);
INSERT INTO one (one_first_var, one_second_var, one_third_var) VALUES (3, 3, 3);

And also a target table (two):

CREATE TABLE two
(
  record_id SERIAL,
  two_first_var INTEGER,
  two_second_var INTEGER,
  two_third_var INTEGER
);

INSERT INTO two (two_first_var, two_second_var, two_third_var) VALUES (21, 21, 21);
INSERT INTO two (two_first_var, two_second_var, two_third_var) VALUES (22, 22, 22);
INSERT INTO two (two_first_var, two_second_var, two_third_var) VALUES (23, 23, 23);

(double check your values in table two):

SELECT * FROM two;

And then run your update (multiple columns at a time):

WITH my_values AS
(
  SELECT 
         one_first_var, 
         one_second_var, 
         one_third_var
  FROM one
  WHERE one_first_var = 2
)
UPDATE two 
SET 
  two_first_var = my_values.one_first_var,
  two_second_var = my_values.one_second_var,
  two_third_var = my_values.one_third_var
FROM
  my_values
WHERE
  two_second_var = 22;

And then re-run your

SELECT * FROM two;

Again, see the SQLFiddle!

You can also use a JOIN to update the target record(s). I would encourage you to experiment with these techniques - very useful!

Your first result for two (i.e. inserted values) will look like this:

record_id   two_first_var   two_second_var  two_third_var
        1              21               21             21
        2              22               22             22
        3              23               23             23

and your second (updated) result will be:

record_id   two_first_var   two_second_var  two_third_var
        2               2                2              2
        1              21               21             21
        3              23               23             23
🌐
Retool
community.retool.com › 💬 queries and resources
How to update multiple rows using a multi select table - 💬 Queries and Resources - Retool Forum
February 4, 2022 - Hi, I am really new to retool and having some trouble updating multiple records based on the user selecting multiple rows in a table. I have created a table that displays data from my database and have successfully upd…