I'm wondering about the following query :
UPDATE statisticsTable
SET Value = (select count(*)
FROM OtherTable o
WHERE o.UserId = UserId ) <-- this is the part that concerns me
WHERE id in (1,2,3)
How does SQL Server know that the second "UserId" field comes from statisticsTable
and not from OtherTable
?
Why can't I give an alias to statisticstable like 'stat' to clarify where I want to get that UserId ? Or is there a way?