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 Solution27 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;

Open in new window

ASKER CERTIFIED SOLUTION
Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 13 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 13 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004