Hi @vy ,
Welcome to the Microsoft SQL Server Q&A Forum!
Regarding your question, I checked some documents.The conclusion drawn from my own perspective is as follows:
When describing the contents of a table, most people usually display the rows in a specific order. But the table actually represents a collection, and the collection has no order. (Tables with clustered index added are stored in the order of the clustered index columns).
The virtual table(there is no order like a normal table) returned by the inner join operator is as follows:
id color id color
1 NULL 1 red
1 NULL 1 blue
The update statement returns a row from the virtual table to update the t1.color column. The column that satisfies the condition t1.id = c.id has two columns. It is uncertain which column is returned.SQL Server will return the row that happened to be accessed first.Therefore, different results may be produced, but they can all be considered correct. If you want to ensure the certainty of the results, you can choose to include a unique order by list.
Take the select statement as an example:
select top(1) *
from c
order by color
The above select statement specifies a unique order by list (the color field is unique), so the returned result is certain.
The result returned by the following statement is not certain (of course they are all considered correct):
select top(1) *
from c
order by id
select top(1) *
from c
In short, SQL Server will return the row that happens to be accessed first, and which row is accessed first is up to the developer.
If you have any question, please feel free to let me know.
If the response is helpful, please click "Accept Answer" and upvote it.
Regards
Echo
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.