(Please forgive all the bad practice elements).The code below results in all flags set to 1. I understand why but should it have done that as I did not qualify I wanted to use mykey from table1.
declare @table1 table (mykey varchar(20), myflag bit)
declare @table2 table (mykey2 varchar(20))
insert into @table1
select 'A',0
insert into @table1
select 'B',0
insert into @table2
select 'Z'
update @table1
set myflag = 1
where mykey in (select mykey from @table2)
Select * from @table1
I would have expected the sql not to be executed as mykey does not exist on table2. When table2 has a field called mykey you can set the statement where mykey in (select mykey from @table2) without any qualification. I am using SQL Server 2017