Need some clarification in SELECT in t-SQL UPDATE statement

Say, if I have the following t-SQL statement (designed to run on SQL Server 2008):

UPDATE tbl
SET col1 = (
    SELECT MAX(col1) FROM tbl AS t1 WHERE t1.type = tbl.type
);

How exactly does SELECT work in this case:

  • He chooses, taking into account the results of each UPDATE, or

  • It selects from tbl, as it was before UPDATE started updating records.

Can anyone clarify this for me?

+5
source share
2 answers

2! Your SELECT subquery pulls the value defined before UPDATE makes any changes.

+4
source

This is 1

1. He chooses according to the results of each UPDATE or

-2
source

All Articles