troubleshooting Question

UDATE Statement with JOIN to Table with Duplicate Rows

Avatar of D B
D BFlag for United States of America asked on
Microsoft SQL Server
13 Comments1 Solution25 ViewsLast Modified:
Running MS SQL Server 2017. I've come across a 'partial' answer to this question but want to go into a bit more detail. I believe, from what I've read, the following code statement is non-deterministic as to what table1.col2 will be set to when table1 has a value of 1 for col1 and table2 has 3 rows with a value of 1 for col1 and 3 different values for col2.

I believe that the answer for my question is, if there is a many-to-many join (e.g. table1 has multiple rows with a value of 1 for col1, will the value of col2 be consistent? I believe it would (e.g. if one row with a value of 1 for col1 gets col2 set to a value of 4, then all rows with a value of 1 for col1 would get col2 set to a value of 4, since the update will be set based).

Neither of these statements are not something that can be easily 'proved' since you need to prove repeatability and how many times do you need to execute code with the same results before you can declare repeatibility? 1,000? 1,000,000? With my luck, the 1,000,001st time would give a different result.

Any internals people out there that would have a definitive answer?
UPDATE a
SET col2 = b.col2
FROM table1 a
INNER JOIN table2 b
ON b.col1 = a.col1;
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 13 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 13 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros