Update query, cross join two tables

The statement reads:
"... , if you write an UPDATE statement with a table A in the UPDATE clause and a table B (but not A) in the FROM clause, you get an implied cross join between A and B."

Question: Could you possibly make #A and #B to demo the effect of this statement?

Based on above, it seems the query will be:

Update #A
Set Age_InA = Age_InB
From #B

Feel free to make your own SQL to better illustrates it. BTW, the book I am studying is using the following example:
UPDATE Sales.MyCustomers
SET MyCustomers.country = SRC.country,
MyCustomers.postalcode = SRC.postalcode
FROM Sales.Customers AS SRC
-- WHERE MyCustomers.custid = SRC.custid;   -- with WHERE clause this will be like inner join.

Open in new window

LVL 34
Mike EghtebasDatabase and Application DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott PletcherSenior DBACommented:
No need for any of this mess and ambiguity in SQL Server.  Just always explicitly join the two in the UPDATE statement:

UPDATE a
SET Age_InA = b.Age_InB
FROM #A a
INNER JOIN #B b ON ... = ...
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Thank you for the comment. I wanted just to see how this acts as cross join running something like:

UPDATE Sales.MyCustomers
SET MyCustomers.country = SRC.country,
MyCustomers.postalcode = SRC.postalcode
FROM Sales.Customers AS SRC

Open in new window


I wanted just to understand this poor method and what kind of damage it causes. This is sort of investigation of a bad process.
0
Scott PletcherSenior DBACommented:
Well, an UPDATE will only update a given row once, so you should get effectively a random row's value in #A / Sales.MyCustomers from #B / Sales.Customers.  That is, a CROSS JOIN (CJ) is every row joined to every row.  But SQL will still only do one UPDATE per row in the updated table.  Since a CJ is not ordered, which row you get from the other table is effectively random.
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Thank you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.