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
sql server - SQL update multiple rows in destination table with same id but different values from source table - Database Administrators Stack Exchange
You stated that the order of the ... 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() ... More on dba.stackexchange.com
🌐 dba.stackexchange.com
August 10, 2017
🌐
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], '') != '' );
🌐
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
🌐
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.
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:
🌐
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 ...
🌐
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…
🌐
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*
🌐
SQL Shack
sqlshack.com › how-to-update-from-a-select-statement-in-sql-server
How to UPDATE from a SELECT statement in SQL Server
May 21, 2021 - The query structure, “UPDATE from SELECT” can be used to perform this type of data update scenario. Also, we can use alternative MERGE statements and subquery methods. ... Esat Erkec is a SQL ...
🌐
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…
Top answer
1 of 5
1

Hi @vy ,

Welcome to the Microsoft SQL Server Q&A Forum!

Regarding your question, I checked some documents.The conclusion drawn from my own perspective is as follows:

When describing the contents of a table, most people usually display the rows in a specific order. But the table actually represents a collection, and the collection has no order. (Tables with clustered index added are stored in the order of the clustered index columns).

The virtual table(there is no order like a normal table) returned by the inner join operator is as follows:

    id  color   id  color  
    1 NULL 1 red  
    1 NULL 1 blue  

The update statement returns a row from the virtual table to update the t1.color column. The column that satisfies the condition t1.id = c.id has two columns. It is uncertain which column is returned.SQL Server will return the row that happened to be accessed first.Therefore, different results may be produced, but they can all be considered correct. If you want to ensure the certainty of the results, you can choose to include a unique order by list.

Take the select statement as an example:

select top(1) *  
from c   
order by color  

The above select statement specifies a unique order by list (the color field is unique), so the returned result is certain.

The result returned by the following statement is not certain (of course they are all considered correct):

select top(1) *  
from c   
order by id  
  
select top(1) *  
from c   

In short, SQL Server will return the row that happens to be accessed first, and which row is accessed first is up to the developer.

If you have any question, please feel free to let me know.
If the response is helpful, please click "Accept Answer" and upvote it.

Regards
Echo


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

2 of 5
1

It's not deterministic. Tom said "random", but that's inexact. As long as the query plan is the same, it is very likely that you will get the same value every time. At least if the plan is serial. But if the plan changes - you could also get a different value.

The important thing is that you cannot rely on anything here. Not even the value being randomly chosen.