Using MSSQL Server 2008 Enterprise Edition and, most likely, other versions of MSSQL, is a proof of concept that makes a temporary table and materializes NEWID () differently depending on whether you use JOIN or LEFT JOIN, although we are juxtaposing the exact two rows .
If you look at the execution plan, you will see that the calculation scalar to get NEWID () is executed last using JOIN, but not when using LEFT JOIN. I would expect LEFT JOIN behavior. Is this weirdness due to naivety in terms of execution or is something else happening?
Demo using the Temp table:
Create Table
With Join, NewParentGuid is different for both strings.
With Left Join, NewParentGuid is the same.
EDIT2: if you add this to the left join, the results will be changed.
where temp2.ParentGuid = temp2.ParentGuid
Or, as another user pointed out, where this column is not zero. They will remain unchanged when performing comparisons in other columns, or where 1 = column 1.Schroedinger?
See also:
Why does newid () materialize at the very end of the request?
John source share