Mike Eghtebas
asked on
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:
"... , 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.
ASKER
Thank you for the comment. I wanted just to see how this acts as cross join running something like:
I wanted just to understand this poor method and what kind of damage it causes. This is sort of investigation of a bad process.
UPDATE Sales.MyCustomers
SET MyCustomers.country = SRC.country,
MyCustomers.postalcode = SRC.postalcode
FROM Sales.Customers AS SRC
I wanted just to understand this poor method and what kind of damage it causes. This is sort of investigation of a bad process.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you.
UPDATE a
SET Age_InA = b.Age_InB
FROM #A a
INNER JOIN #B b ON ... = ...